【发布时间】:2015-10-23 05:38:59
【问题描述】:
今天我正在调试我的 android 应用程序,但它崩溃了。这是调用堆栈:
android.content.res.Resources$NotFoundException: String resource ID #0x8822
at android.content.res.Resources.getText(Resources.java:246)
at android.widget.TextView.setText(TextView.java:3860)
at com.whackanandroid.GameActivity.gameOver(GameActivity.java:68)
at com.whackanandroid.Game$1.onCountDownFinished(Game.java:79)
at com.whackanandroid.CountDown$1.run(CountDown.java:23)
at android.os.Handler.handleCallback(Handler.java:730)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:213)
at android.app.ActivityThread.main(ActivityThread.java:5225)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:741)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
at dalvik.system.NativeStart.main(Native Method)
然后我点击了行号链接 (TextView.java:3860),它把我带到了一行 javadoc 注释。我真的很困惑。评论从不被执行。这不可能是错的。这很奇怪。
这是我的代码:
public void gameOver () {
tvScore.setText (Integer.toString (Game.getInstance ().getScore ()));
tvHighscore.setText (Game.getInstance ().getHighscore ());
tvScoreText.setVisibility (View.VISIBLE);
tvScore.setVisibility (View.VISIBLE);
Animation anim = AnimationUtils.loadAnimation (this, R.anim.cover_fade_in);
anim.setAnimationListener (new Animation.AnimationListener () {
@Override
public void onAnimationStart(Animation animation) {
GameActivity.this.cover.setVisibility (View.VISIBLE);
}
@Override
public void onAnimationEnd(Animation animation) {
GameActivity.this.cover.setVisibility (View.VISIBLE);
Game.InitializeGame (GameActivity.this);
cover.setVisibility (View.VISIBLE);
}
@Override
public void onAnimationRepeat(Animation animation) {
}
});
cover.startAnimation (anim);
}
tvHighscore.setText (Game.getInstance ().getHighscore ()); 行引用调用堆栈中的行:at com.whackanandroid.GameActivity.gameOver(GameActivity.java:68)。我认为这可能是因为 tvHighscore 的父视图 LinearLayout 是 GONE。这有关系吗?还是我做错了什么?
如果您需要查看更多代码,请随时问我。
【问题讨论】:
-
当前源和编译时源的不同版本 - 正常。
-
Android 正在尝试查找具有 int 值的资源 tvHighscore.setText (Game.getInstance ().getHighscore ());