I am having difficulty with the following method. I can't figure out if my problem is, but I have narrowed it down to not populating the array list from the file. Any help is greatly appreciated.
private void searchButtonActionPerformed(java.awt.event.ActionEvent evt) {
//create arraylists
ArrayList<String> model = new ArrayList<String>();
ArrayList<String> length = new ArrayList<String>();
ArrayList<String> width = new ArrayList<String>();
ArrayList<String> radius = new ArrayList<String>();
ArrayList<String> depth = new ArrayList<String>();
ArrayList<String> volume = new ArrayList<String>();
ArrayList<String> shape = new ArrayList<String>();
//fill arraylists from file
try {
String outputline = "";
BufferedReader fin = new BufferedReader(new FileReader("stock.dat"));
while((outputline = fin.readLine()) != null) {
// for(int i = 0; i < outputline.length(); i++) {
int i = 0;
//model
boolean flag = false;
String pass = "";
while(flag = false) {
if(outputline.charAt(i) != ',')
pass.concat(Character.toString(outputline.charAt(i)));
else
flag = true;
i++;
}
model.add(pass);
//length
flag = false;
pass = "";
while(flag = false) {
if(outputline.charAt(i) != ',')
pass.concat(Character.toString(outputline.charAt(i)));
else
flag = true;
}
length.add(pass);
//width
flag = false;
pass = "";
while(flag = false) {
if(outputline.charAt(i) != ',')
pass.concat(Character.toString(outputline.charAt(i)));
else
flag = true;
}
width.add(pass);
//radius
flag = false;
pass = "";
while(flag = false) {
if(outputline.charAt(i) != ',')
pass.concat(Character.toString(outputline.charAt(i)));
else
flag = true;
}
radius.add(pass);
//depth
flag = false;
pass = "";
while(flag = false) {
if(outputline.charAt(i) != ',')
pass.concat(Character.toString(outputline.charAt(i)));
else
flag = true;
}
depth.add(pass);
//volume
flag = false;
pass = "";
while(flag = false) {
if(outputline.charAt(i) != ',')
pass.concat(Character.toString(outputline.charAt(i)));
else
flag = true;
}
volume.add(pass);
//shape
pass = "";
for(int j = i; j < outputline.length(); j++)
pass.concat(Character.toString(outputline.charAt(i)));
shape.add(pass);
}
fin.close();
}
catch(IOException e) {
System.err.print("Unable to read from file");
System.exit(-1);
}
int at = -1;
for(int i = 0; i < model.size(); i++) {
if(model.get(i).equals(searchIn.getText())) {
at = i;
i = model.size();
}
}
Component frame = null;
if(at != -1) {
searchDepthOut.setText(depth.get(at));
searchLengthOut.setText(length.get(at));
searchRadiusOut.setText(radius.get(at));
searchVolumeOut.setText(volume.get(at));
searchWidthOut.setText(width.get(at));
}
else
JOptionPane.showMessageDialog(null, "Your search did not return any results", "ERORR", JOptionPane.ERROR_MESSAGE);
}