gpt4 book ai didi

java - 为什么这个调用堆栈如此奇怪?

转载 作者:行者123 更新时间:2023-12-01 16:56:45 24 4
gpt4 key购买 nike

今天我正在调试我的 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 的父 View LinearLayoutGONE。这有关系吗?还是我做错了什么?

如果您需要查看更多代码,请随时询问我。

最佳答案

Or did I do anything else wrong?

是的。您调用了 setText(int),其值不是字符串资源 ID。变化:

tvHighscore.setText (Game.getInstance ().getHighscore ());

至:

tvHighscore.setText(Integer.toString(Game.getInstance().getHighscore()));

关于java - 为什么这个调用堆栈如此奇怪?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31747908/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com