0

Hi so I'm still learning to use methods, but one of my assignments requires me to call a method from a method in a different .java file.

The problem is "Sets" is not recognized and it displays an error message stating that both "Sets" cannot be resolved to a variable. Am I calling the method incorrectly?

This is the method if it is relevant. It comes from a java file called Sets.

public static final int Initial_Pop = (int)(EARTH_AT * EARTH_BT * 0.4); 

This is the method I'm trying to call the above method..

public static void plusPeople (int[][] earth, int newPerson) { int [][] earthpopulation = new int [Sets.EARTH_AT][Sets.EARTH_BT]; } 

I apologize if I'm unclear or did not provide enough information. If so please tell me!

1
  • Each .java file should have a package declaration at the very top. Are your two classes in the same package? Commented Oct 12, 2012 at 1:41

2 Answers 2

1

You are trying to access EARTH_AT and EARTH_BT and I don't know if these are static. Even though the variable declared is INITIAL_ALIVE_COUNT.

Also remember to check if both classes are in the same Folder (or package). If not, you'll have to import the Sets class.

Sign up to request clarification or add additional context in comments.

1 Comment

I feel silly. I can't believe my classes were not in the same package. I wish I could upvote everyone here :(
0

when you call Sets.EARTH_AT and Sets.EARTH_BT, these are not methods, but rather variables within the Sets class. Make sure these are static variables inside Sets class

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.