简体   繁体   中英

Solving errors with a stacktrace

I got an error that its stacktrace doesn't reveal where in my classes (& line number) the error lies. Is there another way I can locate the code that causes this error?

I understand the error itself... but there are a couple of places in my code that could cause this and I can't reproduce it... (got the stacktrace from a user report).

Here's the stacktrace:

android.view.WindowManager$BadTokenException: Unable to add window -- token android.os.BinderProxy@462e1370 is not valid; is your activity running?
at android.view.ViewRoot.setView(ViewRoot.java:509)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:177)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
at android.view.Window$LocalWindowManager.addView(Window.java:424)
at android.app.Dialog.show(Dialog.java:241)
at android.app.AlertDialog$Builder.show(AlertDialog.java:802)
at android.webkit.CallbackProxy.handleMessage(CallbackProxy.java:566)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:144)
at android.app.ActivityThread.main(ActivityThread.java:4937)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
at dalvik.system.NativeStart.main(Native Method)

Thank you!

You are probably trying to show a dialog when the user has paused or killed the app. Check all your alertDialogs and how you show these. Make sure your activity is running. For example you could use isFinishing

Comment is now an answer as requested:

I'm thinking that the exception is coming from a different thread. This seems to be the event thread of Android while you execute code in the worker thread that results in code being executed in the event thread. Like slayton suggested in his comment add some comments. However, also try to comment out parts of the code and see what line causes that exception.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM