I have 2 classes, Line
and Visual
. Line has a constructor with 2 parameters and Visual contains the main
method and a public static void showEle(ELe e){}
Line also has an arrayList called line that is private, so I have create a get method for that:
public ArrayList<Passenger> getLine(){
return line;
}
Problem arises when I try to call getLine() using line.getLine(), says "cannot find symbol".
public Line obj; <----this is outside showEle method but same class.
The following in showEle method of Visual:
obj.getLine();
but i end up with "non static variable obj cannot be referenced from a static context".
Another way I can do is creating an object but that would require putting parameters because of the constructor in class Line.
Can't think of any other ways to call getLine() method in class Line from a static method in another class.
Code:
public class Visual {
public static void showEle(Ele e){
line.getLine();
}
public static void main(String[] args){
}
}
public class Line {
private ArrayList<Passenger> line = new ArrayList<>();
public ArrayList<Passenger> getLine(){
return line;
}
}