-
Notifications
You must be signed in to change notification settings - Fork 337
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TranslationLayout NullPointerException #42
Comments
I can't get when it happends and it happends rarely. It seems to be randomly, but could happen when I open poups that not are on the map but is placed on top of it. These ones also get some data. Sometimes it just crashes when I have it open. It feels like the views has been garbage collected or something. I have a lot of markers on my map, at least 100. And some objects that are moving on it. |
Done some more digging. I think the problem is when I remove a marker. My theory is that onMeasure in TranslationLayout is running and the view is removed while it is running measureChildren and then it have a discapency between mChildrenCount and the actual number of children (see http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/4.0.3_r1/android/view/ViewGroup.java#ViewGroup.measureChildren%28int%2Cint%29). Possible? I'm gonna look deeper into it tomorrow. |
Hm... Of course I can't tell without seeing the code and debugging myself, but I'd be surprised if that were the issue. Almost all overridden onLayout/onMeasure methods I've seen do the same basic loop. Should be easy to tell, though - just wrap it in a try/catch or add a null check:
or
Or maybe test the count in the evaluation expression, so instead of:
You could try
I'd be interested to hear what you discover. |
Yeah, I feel the same way. It feels a bit strange that there could be a syncronization problem there. Just a note, it mostly happends in: TranslationLayout.java - onMeasure:
ViewGroup.java
I'm gonna do some testing now! |
I'm not any closer. I catch the NPE with a try around all code in onMeasure but then it fails in onLayout :/ And the state of the NPE didn't give me that much.. But I'm gonna try to write out the index of the child that is null. Unfortunately I can't reproduce the error so it is really hard debugging. New day tomorrow... Any ideas? And I'm thinking, I have 150+ children. Does it not take relatively long time to loop them and couldn't one get removed and cause that nullpointer.. ? Feels unlikeley but a possability.. Thanks. |
If wrapping onMeasure with try/catch pushed the NPE off to onLayout, it sounds like you're on the right track at least. I'd try those simple tricks above in both, and see what happens. That said - notice that your stack trace shows the error on line 46 - line 46 is the call to Regarding this:
I don't think so. I'm not 100% sure, but AFAIK, that could only happen if the two actions (onMeasure, and removal) happened in different threads. To clarify: the NPE only happens when you remove markers? |
I am actually not sure when it happends. It was my theory that it happened when I removed a marker. I havn't yet found a way to trigger the error. That's the key. Will try removing add adding a lot tomorrow. No, normally it is not direct in the loop. It is in the ViewGroup.java method I'm still confused how a child can be null... |
post back if i can help |
@tekblom did you get this worked out? or should i leave this issue open? |
Hi,
I get an error that make my app crash. It says that it is a problem in the TranslationLayout. Right before the stacktrace that i add below I get this warning:
threadid=1: thread exiting with uncaught exception (group=0x40bed1f8)
Stacktrace:
dalvik.system.NativeStart ? in main at line -2
com.android.internal.os.ZygoteInit ? in main at line 745
com.android.internal.os.ZygoteInit$MethodAndArgsCaller ? in run at line 978
java.lang.reflect.Method ? in invoke at line 511
java.lang.reflect.Method ? in invokeNative at line -2
android.app.ActivityThread ? in main at line 4507
android.os.Looper ? in loop at line 137
android.os.Handler ? in dispatchMessage at line 99
android.view.ViewRootImpl ? in handleMessage at line 2649
android.view.ViewRootImpl ? in performTraversals at line 1255
android.view.View ? in measure at line 12922
com.android.internal.policy.impl.PhoneWindow$DecorView ? in onMeasure at line 2261
android.widget.FrameLayout ? in onMeasure at line 293
android.view.ViewGroup ? in measureChildWithMargins at line 4706
android.view.View ? in measure at line 12922
android.widget.LinearLayout ? in onMeasure at line 563
android.widget.LinearLayout ? in measureVertical at line 670
android.widget.LinearLayout ? in measureChildBeforeLayout at line 1385
android.view.ViewGroup ? in measureChildWithMargins at line 4706
android.view.View ? in measure at line 12922
android.widget.FrameLayout ? in onMeasure at line 293
android.view.ViewGroup ? in measureChildWithMargins at line 4706
android.view.View ? in measure at line 12922
android.widget.RelativeLayout ? in onMeasure at line 376
android.widget.RelativeLayout ? in measureChildHorizontal at line 594
android.view.View ? in measure at line 12922
android.widget.RelativeLayout ? in onMeasure at line 392
android.widget.RelativeLayout ? in measureChild at line 579
android.view.View ? in measure at line 12922
android.widget.RelativeLayout ? in onMeasure at line 376
android.widget.RelativeLayout ? in measureChildHorizontal at line 594
android.view.View ? in measure at line 12922
android.widget.RelativeLayout ? in onMeasure at line 376
android.widget.RelativeLayout ? in measureChildHorizontal at line 594
android.view.View ? in measure at line 12922
com.qozix.layouts.ZoomPanLayout ? in onMeasure at line 438
android.view.ViewGroup ? in measureChildren at line 4654
android.view.ViewGroup ? in measureChild at line 4677
android.view.View ? in measure at line 12922
com.qozix.layouts.StaticLayout ? in onMeasure at line 16
android.view.ViewGroup ? in measureChildren at line 4654
android.view.ViewGroup ? in measureChild at line 4677
android.view.View ? in measure at line 12922
com.qozix.layouts.TranslationLayout ? in onMeasure at line 46
android.view.ViewGroup ? in measureChildren at line 4653
Caused by: java.lang.NullPointerException ? at line -1
Do you have any ideas?
The text was updated successfully, but these errors were encountered: