public class Thing
{
public static void main (String[] args)
{
//I set my veriables and prompt user to enter number of names
//Prompt user for First and Last name and Store names in an array of classes
Arrays.sort(listOfName, new Comparator<otherClass>()//Sort names according to last name
//code here for that (which i have but not the issue)
for (int i = 0; i<numName; i++)
{
ans = JOptionPane.showInputDialog(null,"How Many Students does: \n "+ listOfName[i]+ " Have");
int val = Integer.parseInt(ans);
otherClass.setnumStudents(val);// in my Separate class I have a setnumStudents
}
for(int i = 0; i<numName; i++)
{
System.out.println(listOfName[i]);
}
}
Earlier in my program I set my array to store according to the separate class otherClass
and the int numStudents
is set to 0 initially, after collecting firstName and lastName I then alphabetize the array and then inquire how many students each person has. Using setter setnumStudents
I try to change the numStudents
stored in the array. With my code as is I get this error:
non-static method setnumStudents(int) cannot be referenced from a static context
otherClass.setnumStudents(val);
^
Thank you for any help on this issue