views:

1780

answers:

3

I am having some of the following exceptions:

java.lang.IllegalArgumentException: View not attached to window manager at android.view.WindowManagerImpl.findViewLocked(WindowManagerImpl.java:355) at android.view.WindowManagerImpl.updateViewLayout(WindowManagerImpl.java:191) at android.view.Window$LocalWindowManager.updateViewLayout(Window.java:428) at android.app.Dialog.onWindowAttributesChanged(Dialog.java:596) at android.view.Window.setDefaultWindowFormat(Window.java:1013) at com.android.internal.policy.impl.PhoneWindow.access$700(PhoneWindow.java:86) at com.android.internal.policy.impl.PhoneWindow$DecorView.drawableChanged(PhoneWindow.java:1951) at com.android.internal.policy.impl.PhoneWindow$DecorView.fitSystemWindows(PhoneWindow.java:1889) at android.view.ViewRoot.performTraversals(ViewRoot.java:727) at android.view.ViewRoot.handleMessage(ViewRoot.java:1633) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:123) at android.app.ActivityThread.main(ActivityThread.java:4338) 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:860) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618) at dalvik.system.NativeStart.main(Native Method)

I have googled it and see that it has something to do with popups and turning the screen, but there is no reference to my code.

The questions are:

  1. is there a way to find out exactly when this issue is happening?
  2. other than turning the screen, is there another event or action that triggers this error?
  3. how do I prevent this to happen?
+1  A: 

For question 1):

Considering that the error message doesn't seem to say which line of your code is causing the trouble, you can track it down by using breakpoints. Breakpoints pause the execution of the program when the program gets to specific lines of code. By adding breakpoints to critical locations, you can determine which line of code causes the crash. For example, if your program is crashing at a setContentView() line, you could put a breakpoint there. When the program runs, it will pause before running that line. If then resuming causes the program to crash before reaching the next breakpoint, you then know that the line that killed the program was between the two breakpoints.

Adding breakpoints is easy if you're using Eclipse. Right click in the margin just to the left of your code and select "Toggle breakpoint". You then need to run your application in debug mode, the button that looks like a green insect next to the normal run button. When the program hits a breakpoint, Eclipse will switch to the debug perspective and show you the line it is waiting at. To start the program running again, look for the 'Resume' button, which looks like a normal 'Play' but with a vertical bar to the left of the triangle.

You can also fill your application with Log.d("My application", "Some information here that tells you where the log line is"), which then posts messages in Eclipse's LogCat window. If you can't find that window, open it up with Window -> Show View -> Other... -> Android -> LogCat.

Hope that helps!

Steve H
The issue is happening on the clients phones, so I dont have an option to debug. Also the issue is happening all the time, just happening sometimes, so dont know how to track it
Daniel Benedykt
You can still get debugging messages from a phone, if you can get your hands on one. In menu -> settings -> applications -> development, there's an option for USB Debugging. If enabled, you can then plug the phone in and LogCat catches all the normal debugging lines. Other than that... well... the intermittency could be explained by it depending on the state of the program. I suppose you'd have to mess around using the program to see if you could recreate the issue.
Steve H
As I said before, the issue is happening on a client phone, and I dont have access to it. The client may be on another continent :)
Daniel Benedykt
There are apps on the market that will email you their logcat.
Tim Green
A: 

I have just wrapped my call in a try / catch block and hoped for the best. I hope that it does not leave the Alert dialog open always, but at least it won't crash on them

gregm
+1  A: 

Actually not my answer. I think this is the same issue as encoutered at http://stackoverflow.com/questions/1111980/how-to-handle-screen-orientation-change-when-progress-dialog-and-background-threa. See solution there.

shoren