Why is this call stack so weird?

早过忘川 提交于 2019-12-25 06:59:03

问题


Today I was debugging my android app and it crashes. Here is the call stack:

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)

Then I clicked on the line number links (TextView.java:3860) and it took me to a line of javadoc comment. I was really confused. Comments never get executed. That can't be wrong. This is strange.

Here is my code:

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);
}

The line tvHighscore.setText (Game.getInstance ().getHighscore ()); refers to the line in the call stack: at com.whackanandroid.GameActivity.gameOver(GameActivity.java:68). I think it might be because tvHighscore's parent view, a LinearLayout is GONE. Does this matter? Or did I do anything else wrong?

If you need to see more code, feel free to ask me.


回答1:


Or did I do anything else wrong?

Yes. You called setText(int), with a value that is not a string resource ID. Change:

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

to:

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



回答2:


If the jar is pulled in as a dependency and you are debugging that then the lines are from the class file that is created by the complier and not java class it self you have to go my the method name and other information. You cannot always rely on the line number.

Another reason can be different version of current source that you are using to see line number and jar that is pulled in is of different version.




回答3:


The problem is that you are using the setText with an integer parameter, this means a resource id.

To solve your problem you could do this:

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


来源:https://stackoverflow.com/questions/31747908/why-is-this-call-stack-so-weird

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!