I am reading data from a file and want to populate several comboBoxes and JText fields. At first I tried reading the data into arrayLists and than populating the fields. I keep on getting "a primative type int error."
Could someone please look at my code and help me identify my error. The class is called from an menu using the Open File option. The agmodTest class holds the comboBox and JText components. Thanks...Ronnie
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.StringTokenizer;
import javax.swing.JFileChooser;
public class open implements ActionListener{
File fileName;
String line, mnth;
int i = 0;
public void actionPerformed(ActionEvent ae){
// create new JFileChooser object and set the location to the current directory.
JFileChooser fc = new JFileChooser(".");
File file = null;
fc.setDialogTitle("Browse for text file");
fc.setApproveButtonToolTipText("Open File");
fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
//get the input of the user (open, or cancel) store the value as an int
int selected = fc.showOpenDialog(null);
//based on the input of the user use a switch statement to execute the correct actions
switch (selected) {
case JFileChooser.APPROVE_OPTION:
file = fc.getSelectedFile();
//set the file just retrieved to the file variable declared at the top of the class.
this.fileName = file;
try{
BufferedReader finhandle = new BufferedReader(new FileReader(fileName));
while((line = finhandle.readLine()) != null) {
// gets comma delimited data
String temp ="," ;
//gets the index of the first character of the string.
int ind = line.indexOf(temp);
String pidAndGrade = line.substring(0, line.length()); // gets the pid and the following submissions
//creates a new string for the pid and grade
StringTokenizer st = new StringTokenizer(pidAndGrade, ",", false);
i = 0;
while (st.hasMoreTokens()){
agmodTest.cupName = (st.nextToken().trim());
agmodTest.countyIndex.setSelectedIndex(Integer.parseInt(st.nextToken().trim());
agmodTest.aWUCAIndex.setIndex(Integer.valueOf((String) st.nextToken().trim()).intValue());
agmodTest.aCropIndex.add(i, st.nextToken().trim());
i++;
}
} //end while loop
}//end try
catch(Exception e){
System.out.println ("Error with open file class..." + e);
e.printStackTrace();
}
}
Could someone please look at my code and help me identify my error. The class is called from an menu using the Open File option. The agmodTest class holds the comboBox and JText components. Thanks...Ronnie
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.StringTokenizer;
import javax.swing.JFileChooser;
public class open implements ActionListener{
File fileName;
String line, mnth;
int i = 0;
public void actionPerformed(ActionEvent ae){
// create new JFileChooser object and set the location to the current directory.
JFileChooser fc = new JFileChooser(".");
File file = null;
fc.setDialogTitle("Browse for text file");
fc.setApproveButtonToolTipText("Open File");
fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
//get the input of the user (open, or cancel) store the value as an int
int selected = fc.showOpenDialog(null);
//based on the input of the user use a switch statement to execute the correct actions
switch (selected) {
case JFileChooser.APPROVE_OPTION:
file = fc.getSelectedFile();
//set the file just retrieved to the file variable declared at the top of the class.
this.fileName = file;
try{
BufferedReader finhandle = new BufferedReader(new FileReader(fileName));
while((line = finhandle.readLine()) != null) {
// gets comma delimited data
String temp ="," ;
//gets the index of the first character of the string.
int ind = line.indexOf(temp);
String pidAndGrade = line.substring(0, line.length()); // gets the pid and the following submissions
//creates a new string for the pid and grade
StringTokenizer st = new StringTokenizer(pidAndGrade, ",", false);
i = 0;
while (st.hasMoreTokens()){
agmodTest.cupName = (st.nextToken().trim());
agmodTest.countyIndex.setSelectedIndex(Integer.parseInt(st.nextToken().trim());
agmodTest.aWUCAIndex.setIndex(Integer.valueOf((String) st.nextToken().trim()).intValue());
agmodTest.aCropIndex.add(i, st.nextToken().trim());
i++;
}
} //end while loop
}//end try
catch(Exception e){
System.out.println ("Error with open file class..." + e);
e.printStackTrace();
}
}