Bug 13615 - FragmentPager on 4.8
Summary: FragmentPager on 4.8
Status: RESOLVED UPSTREAM
Alias: None
Product: Android
Classification: Xamarin
Component: Mono runtime / AOT Compiler ()
Version: 4.8.x
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Jonathan Pryor
URL:
Depends on:
Blocks:
 
Reported: 2013-07-30 12:01 UTC by Goncalo Oliveira
Modified: 2013-08-05 14:18 UTC (History)
2 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED UPSTREAM

Description Goncalo Oliveira 2013-07-30 12:01:14 UTC
I'm having a weird crash on one of my applications when recently building with 4.8.

To note that I haven't made changes to this project in a while and it was working fine with the previous 4.6 release.

Everytime I deploy the application to the device, the first time it runs, it throws a weird exception that seems to be related with a ViewPager. If trying to debug, I can't trap any exception, I just get the android window saying the app has stopped unexpectedly. I retry and it all goes well.

Not really sure what's causing the problem, though, any thoughts are welcome.

Here's the stacktrace. Nothing relevant before or after.

07-30 16:40:26.410: D/AndroidRuntime(2801): Shutting down VM
07-30 16:40:26.410: W/dalvikvm(2801): threadid=1: thread exiting with uncaught exception (group=0x40222760)
07-30 16:40:26.410: E/AndroidRuntime(2801): FATAL EXCEPTION: main
07-30 16:40:26.410: E/AndroidRuntime(2801): java.lang.NullPointerException
07-30 16:40:26.410: E/AndroidRuntime(2801): 	at android.support.v4.app.BackStackRecord.doAddOp(BackStackRecord.java:394)
07-30 16:40:26.410: E/AndroidRuntime(2801): 	at android.support.v4.app.BackStackRecord.add(BackStackRecord.java:389)
07-30 16:40:26.410: E/AndroidRuntime(2801): 	at android.support.v4.app.FragmentPagerAdapter.instantiateItem(FragmentPagerAdapter.java:99)
07-30 16:40:26.410: E/AndroidRuntime(2801): 	at android.support.v4.view.ViewPager.addNewItem(ViewPager.java:829)
07-30 16:40:26.410: E/AndroidRuntime(2801): 	at android.support.v4.view.ViewPager.populate(ViewPager.java:979)
07-30 16:40:26.410: E/AndroidRuntime(2801): 	at android.support.v4.view.ViewPager.populate(ViewPager.java:911)
07-30 16:40:26.410: E/AndroidRuntime(2801): 	at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1432)
07-30 16:40:26.410: E/AndroidRuntime(2801): 	at android.view.View.measure(View.java:10835)
07-30 16:40:26.410: E/AndroidRuntime(2801): 	at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4351)
07-30 16:40:26.410: E/AndroidRuntime(2801): 	at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1284)
07-30 16:40:26.410: E/AndroidRuntime(2801): 	at android.widget.LinearLayout.measureVertical(LinearLayout.java:613)
07-30 16:40:26.410: E/AndroidRuntime(2801): 	at android.widget.LinearLayout.onMeasure(LinearLayout.java:519)
07-30 16:40:26.410: E/AndroidRuntime(2801): 	at android.view.View.measure(View.java:10835)
07-30 16:40:26.410: E/AndroidRuntime(2801): 	at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4351)
07-30 16:40:26.410: E/AndroidRuntime(2801): 	at android.widget.FrameLayout.onMeasure(FrameLayout.java:267)
07-30 16:40:26.410: E/AndroidRuntime(2801): 	at android.view.View.measure(View.java:10835)
07-30 16:40:26.410: E/AndroidRuntime(2801): 	at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4351)
07-30 16:40:26.410: E/AndroidRuntime(2801): 	at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1284)
07-30 16:40:26.410: E/AndroidRuntime(2801): 	at android.widget.LinearLayout.measureVertical(LinearLayout.java:613)
07-30 16:40:26.410: E/AndroidRuntime(2801): 	at android.widget.LinearLayout.onMeasure(LinearLayout.java:519)
07-30 16:40:26.410: E/AndroidRuntime(2801): 	at android.view.View.measure(View.java:10835)
07-30 16:40:26.410: E/AndroidRuntime(2801): 	at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4351)
07-30 16:40:26.410: E/AndroidRuntime(2801): 	at android.widget.FrameLayout.onMeasure(FrameLayout.java:267)
07-30 16:40:26.410: E/AndroidRuntime(2801): 	at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:1889)
07-30 16:40:26.410: E/AndroidRuntime(2801): 	at android.view.View.measure(View.java:10835)
07-30 16:40:26.410: E/AndroidRuntime(2801): 	at android.view.ViewRoot.performTraversals(ViewRoot.java:944)
07-30 16:40:26.410: E/AndroidRuntime(2801): 	at android.view.ViewRoot.handleMessage(ViewRoot.java:2046)
07-30 16:40:26.410: E/AndroidRuntime(2801): 	at android.os.Handler.dispatchMessage(Handler.java:99)
07-30 16:40:26.410: E/AndroidRuntime(2801): 	at android.os.Looper.loop(Looper.java:132)
07-30 16:40:26.410: E/AndroidRuntime(2801): 	at android.app.ActivityThread.main(ActivityThread.java:4123)
07-30 16:40:26.410: E/AndroidRuntime(2801): 	at java.lang.reflect.Method.invokeNative(Native Method)
07-30 16:40:26.410: E/AndroidRuntime(2801): 	at java.lang.reflect.Method.invoke(Method.java:491)
07-30 16:40:26.410: E/AndroidRuntime(2801): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
07-30 16:40:26.410: E/AndroidRuntime(2801): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
07-30 16:40:26.410: E/AndroidRuntime(2801): 	at dalvik.system.NativeStart.main(Native Method)
Comment 1 Jonathan Pryor 2013-07-30 22:46:39 UTC
Note that 4.6.8 changed the android-support-v4.jar that we bind and ship from revision 11 (I think, or earlier!) to revision 13. 4.8.0 likewise binds and ships android-support-v4.jar revision 13.

> To note that I haven't made changes to this project in a while and it was
> working fine with the previous 4.6 release.

What was the 4.6 release you were previously using? If it's been awhile, it likely was not the 4.6.8 release, which means it was a different version of the support library. Does it still fail if you use the 4.6.8 release?

I suspect what you're seeing is an issue within android-support-v4.jar itself.

> If trying to debug, I can't trap any exception, I just get the android window
> saying the app has stopped unexpectedly

This is because when the exception occurs there is no C# stack frame in the stack trace. (Transitions from Java to C# are easy to notice as these are methods with an "n_" prefix, and no such methods appear in your provided stack trace.)

To catch and report this error, you'd have to try setting Thread.DefaultUncaughtExceptionHandler:

http://androidapi.xamarin.com/?link=P%3aJava.Lang.Thread.DefaultUncaughtExceptionHandler
Comment 2 Goncalo Oliveira 2013-07-31 05:56:23 UTC
Jon,

Thanks for replying. I implemented the DefaultUncaughtExceptionHandler, the trace is below. Doesn't really say more than before :/ I also tried removing the Mono.Android.Support.v4.dll replacing it with Mono.Android.Support.v13.dll, the result is the same.

UncaughtExceptionHandler >
07-31 10:31:21.940: E/FMobileApplication(5911): Java.Lang.NullPointerException: Exception of type 'Java.Lang.NullPointerException' was thrown.
07-31 10:31:21.940: E/FMobileApplication(5911):   --- End of managed exception stack trace ---
07-31 10:31:21.940: E/FMobileApplication(5911): java.lang.NullPointerException
07-31 10:31:21.940: E/FMobileApplication(5911): 	at android.support.v4.app.BackStackRecord.doAddOp(BackStackRecord.java:394)
07-31 10:31:21.940: E/FMobileApplication(5911): 	at android.support.v4.app.BackStackRecord.add(BackStackRecord.java:389)
07-31 10:31:21.940: E/FMobileApplication(5911): 	at android.support.v4.app.FragmentPagerAdapter.instantiateItem(FragmentPagerAdapter.java:99)
07-31 10:31:21.940: E/FMobileApplication(5911): 	at android.support.v4.view.ViewPager.addNewItem(ViewPager.java:829)
07-31 10:31:21.940: E/FMobileApplication(5911): 	at android.support.v4.view.ViewPager.populate(ViewPager.java:979)
07-31 10:31:21.940: E/FMobileApplication(5911): 	at android.support.v4.view.ViewPager.populate(ViewPager.java:911)
07-31 10:31:21.940: E/FMobileApplication(5911): 	at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1432)
07-31 10:31:21.940: E/FMobileApplication(5911): 	at android.view.View.measure(View.java:10835)
07-31 10:31:21.940: E/FMobileApplication(5911): 	at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4351)
07-31 10:31:21.940: E/FMobileApplication(5911): 	at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1284)
07-31 10:31:21.940: E/FMobileApplication(5911): 	at android.widget.LinearLayout.measureVertical(LinearLayout.java:613)
07-31 10:31:21.940: E/FMobileApplication(5911): 	at android.widget.LinearLayout.onMeasure(LinearLayout.java:519)
07-31 10:31:21.940: E/FMobileApplication(5911): 	at android.view.View.measure(View.java:10835)
07-31 10:31:21.940: E/FMobileApplication(5911): 	at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4351)
07-31 10:31:21.940: E/FMobileApplication(5911): 	at android.widget.FrameLayout.onMeasure(FrameLayout.java:267)
07-31 10:31:21.940: E/FMobileApplication(5911): 	at android.view.View.measure(View.java:10835)
07-31 10:31:21.940: E/FMobileApplication(5911): 	at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4351)
07-31 10:31:21.940: E/FMobileApplication(5911): 	at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1284)
07-31 10:31:21.940: E/FMobileApplication(5911): 	at android.widget.LinearLayout.measureVertical(LinearLayout.java:613)
07-31 10:31:21.940: E/FMobileApplication(5911): 	at android.widget.LinearLayout.onMeasure(LinearLayout.java:519)
07-31 10:31:21.940: E/FMobileApplication(5911): 	at android.view.View.measure(View.java:10835)
07-31 10:31:21.940: E/FMobileApplication(5911): 	at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4351)
07-31 10:31:21.940: E/FMobileApplication(5911): 	at android.widget.FrameLayout.onMeasure(FrameLayout.java:267)
07-31 10:31:21.940: E/FMobileApplication(5911): 	at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:1889)
07-31 10:31:21.940: E/FMobileApplication(5911): 	at android.view.View.measure(View.java:10835)
07-31 10:31:21.940: E/FMobileApplication(5911): 	at android.view.ViewRoot.performTraversals(ViewRoot.java:944)
07-31 10:31:21.940: E/FMobileApplication(5911): 	at android.view.ViewRoot.handleMessage(ViewRoot.java:2046)
07-31 10:31:21.940: E/FMobileApplication(5911): 	at android.os.Handler.dispatchMessage(Handler.java:99)
07-31 10:31:21.940: E/FMobileApplication(5911): 	at android.os.Looper.loop(Looper.java:132)
07-31 10:31:21.940: E/FMobileApplication(5911): 	at android.app.ActivityThread.main(ActivityThread.java:4123)
07-31 10:31:21.940: E/FMobileApplication(5911): 	at java.lang.reflect.Method.invokeNative(Native Method)
07-31 10:31:21.940: E/FMobileApplication(5911): 	at java.lang.reflect.Method.invoke(Method.java:491)
07-31 10:31:21.940: E/FMobileApplication(5911): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
07-31 10:31:21.940: E/FMobileApplication(5911): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
07-31 10:31:21.940: E/FMobileApplication(5911): 	at dalvik.system.NativeStart.main(Native Method)
Comment 3 Goncalo Oliveira 2013-07-31 06:48:00 UTC
Ok, I've been able to go around the issue.

Some additional facts

1. The main activity (with the fragments viewpager) is marked with [Activity( LaunchMode = Android.Content.PM.LaunchMode.SingleTask )]

2. The activity onResume calls StartActivityForResult if there is no user information stored yet (so it's invoking a login activity).


What seems to be the problem is that the viewpager does not have time to be correctly initialized; if I don't invoke the second activity, nothing happens, and this is why it only happens the first time - because all the consecutive tries already have user information stored (if I kill the process, clear data and go again, the problem still goes).

To see if the theory was right, I first commented the call to StartActivityForResult from onResume. It worked. So, afterwards, I enveloped the StartActivityForResult call in RunOnUiThread inside a Thread after a Thread.Sleep(). It worked.

This wasn't happening in an earlier version, so you're probably right Jon, has to do with the new support binding revision. I was always on stable channel, so my previous version was 4.6.0 which didn't have the new binding.

Obviously this can be worked around by having a preceding activity calling either login or main activities based on the user information, but I'm guessing this doesn't make it right.

Cheers.
Comment 4 Jonathan Pryor 2013-08-05 14:18:28 UTC
Closing as UPSTREAM as per Comment #3: it appears to be an issue with android-support-v4.jar.