尝试访问静态变量时Android Studio抛出错误

时间:2017-11-29 01:41:05

标签: java android static

这是我的代码:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_hangman_guess);
    TextView t = (TextView) findViewById(R.id.lives);
    String s = "";
    for (int i = 0; i < WordHandler.lives; i++) // Error on this line
        s += new String(Character.toChars(0x2764));
    t.setText(s);
}

当我运行此代码时,我在注释行上得到java.lang.ExceptionInInitializerError,这是由以下行的android.content.res.Resources$NotFoundException引起的:

public static String word = Resources.getSystem().getString(R.string.default_word);

变量WordHandler.lives定义为public static int lives = 5; 为什么抛出此异常?我不能拨打Resources.getSystem()吗?

0 个答案:

没有答案