I am writing objects to an arraylist in which I need to access particular elements of the object. However, I keep getting this annoying error. My load class just has setters for the elements within the objects. How do I fix it? I am just wanting to assign that particular element to a variable.
Driver class
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class Driver {
public static void main(String[] args) throws IOException
{
BufferedReader file = new BufferedReader(new FileReader("test.txt"));
ArrayList<Load> list = new ArrayList<Load>();
String line;
String[] words=new String[3] ;
Load load = new Load();
int x =0;
while((line=file.readLine())!=null)
{
words=line.split("\t");
String process=words[0];
int arrivalTime=Integer.parseInt(words[1]);
int serviceTime=Integer.parseInt(words[2]);
list.add(new Load(process,arrivalTime,serviceTime));
x++;
}
}
}
RoundRobin class
public class RoundRobin {
Driver data = new Driver();
String a =((Load) data.list.get(0)).process; //This is where the error occurs
}