我有一个要在 2 个类之间传递的值,但出现以下错误:
令牌“;”上的语法错误,从另一个类初始化调用值时预期
我有初始值的类
public class Game extends Activity implements OnClickListener{
RandomMathQuestionGenerator question = new RandomMathQuestionGenerator();
private static final String TAG= "Sudoku";
public static final String KEY_DIFFICULTY =
"org.example.sudoku.difficulty";
public static final int DIFFICULTY_NOVICE = 1;
public static final int DIFFICULTY_EASY = 2;
public static final int DIFFICULTY_MEDIUM = 3;
public static final int DIFFICULTY_GURU = 4;
public int value = 0;
private GameView gameView;
public Game()
{
if (KEY_DIFFICULTY == String.valueOf(1))
{
value = 2;
}
else if (KEY_DIFFICULTY == String.valueOf(2))
{
value = 3;
}
else if (KEY_DIFFICULTY == String.valueOf(3))
{
value = 4;
}
else if (KEY_DIFFICULTY == String.valueOf(4))
{
value = 6;
}
}
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.d(TAG, "onCreate");
}
@Override
public void onClick(View v)
{
//code here
}
}
我称之为值的类
public class RandomMathQuestionGenerator {
Game num = new Game();
int number = 0;
number = num.Game(value);
//public int number = 0;
//number = num.Game(number);
private static final int NUMBER_OF_QUESTIONS = 1;
private static final int MIN_QUESTION_ELEMENTS = 2;
private final int MAX_QUESTION_ELEMENTS = number;
private static final int MIN_QUESTION_ELEMENT_VALUE = 1;
private static final int MAX_QUESTION_ELEMENT_VALUE = 100;
private final Random randomGenerator = new Random();
//rest of irrelevant code below
}