Xamarin.Forms Android StackOverflowError与TabbedPage

时间:2016-11-02 16:35:39

标签: xamarin xamarin.forms tabbedpage

我正面临着Xamarin.Forms的问题,尤其是Android上的TabbedPage问题。

我创建了一个包含4个ContentPage的TabbedPage。每个ContentPage都包含一个带有自定义ItemTemplate的ListView(XAML中超过50行)。它在iOS上工作正常,但在Android上却没有,我收到了这个例外:

Java.Lang.StackOverflowError: 
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /Users/builder/data/lanes/3819/96c7ba6c/source/mono/mcs/class/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:143
  at Java.Interop.JniEnvironment+InstanceMethods.CallNonvirtualVoidMethod (Java.Interop.JniObjectReference instance, Java.Interop.JniObjectReference type, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue* args) [0x000a7] in /Users/builder/data/lanes/3819/96c7ba6c/source/Java.Interop/src/Java.Interop/Java.Interop/JniEnvironment.g.cs:12083
  at Java.Interop.JniPeerMembers+JniInstanceMethods.InvokeVirtualVoidMethod (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters) [0x00068] in /Users/builder/data/lanes/3819/96c7ba6c/source/Java.Interop/src/Java.Interop/Java.Interop/JniPeerMembers.JniInstanceMethods_Invoke.cs:31
  at Android.Views.View.Draw (Android.Graphics.Canvas canvas) [0x0002c] in /Users/builder/data/lanes/3819/96c7ba6c/source/monodroid/src/Mono.Android/platforms/android-24/src/generated/Android.Views.View.cs:12837
  at Xamarin.Forms.Platform.Android.ScrollViewRenderer.Draw (Android.Graphics.Canvas canvas) [0x0000d] in C:\BuildAgent2\work\ca3766cfc22354a1\Xamarin.Forms.Platform.Android\Renderers\ScrollViewRenderer.cs:99
  at Android.Views.View.n_Draw_Landroid_graphics_Canvas_ (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_canvas) [0x00011] in /Users/builder/data/lanes/3819/96c7ba6c/source/monodroid/src/Mono.Android/platforms/android-24/src/generated/Android.Views.View.cs:12825
  at at (wrapper dynamic-method) System.Object:75413b68-d1a4-4864-b7a4-6d3fd2662bd8 (intptr,intptr,intptr)
  at java.lang.StackOverflowError
  at at android.graphics.Paint.getTextRunAdvances(Paint.java:2221)
  at at android.text.TextLine.handleText(TextLine.java:815)
  at at android.text.TextLine.handleRun(TextLine.java:970)
  at at android.text.TextLine.measureRun(TextLine.java:482)
  at at android.text.TextLine.measure(TextLine.java:361)
  at at android.text.TextLine.metrics(TextLine.java:335)
  at at android.text.Layout.getLineExtent(Layout.java:1001)
  at at android.text.Layout.drawText(Layout.java:332)
  at at android.text.Layout.draw(Layout.java:208)
  at at android.text.BoringLayout.draw(BoringLayout.java:403)
  at at android.widget.TextView.onDraw(TextView.java:6286)
  at at android.view.View.draw(View.java:15312)
  at at android.view.View.getDisplayList(View.java:14206)
  at at android.view.View.getDisplayList(View.java:14248)
  at at android.view.View.draw(View.java:15026)
  at at android.view.ViewGroup.drawChild(ViewGroup.java:3307)
  at at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3144)
  at at android.view.View.getDisplayList(View.java:14201)
  at at android.view.View.getDisplayList(View.java:14248)
  at at android.view.View.draw(View.java:15026)
  at at android.view.ViewGroup.drawChild(ViewGroup.java:3307)
  at at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3144)
  at at android.view.View.getDisplayList(View.java:14201)
  at at android.view.View.getDisplayList(View.java:14248)
  at at android.view.View.draw(View.java:15026)
  at at android.view.ViewGroup.drawChild(ViewGroup.java:3307)
  at at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3144)
  at at android.view.View.getDisplayList(View.java:14201)
  at at android.view.View.getDisplayList(View.java:14248)
  at at android.view.View.draw(View.java:15026)
  at at android.view.ViewGroup.drawChild(ViewGroup.java:3307)
  at at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3144)
  at at android.view.View.getDisplayList(View.java:14201)
  at at android.view.View.getDisplayList(View.java:14248)
  at at android.view.View.draw(View.java:15026)
  at at android.view.ViewGroup.drawChild(ViewGroup.java:3307)
  at at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3144)
  at at android.view.View.getDisplayList(View.java:14201)
  at at android.view.View.getDisplayList(View.java:14248)
  at at android.view.View.draw(View.java:15026)
  at at android.view.ViewGroup.drawChild(ViewGroup.java:3307)
  at at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3144)
  at at android.view.View.getDisplayList(View.java:14201)
  at at android.view.View.getDisplayList(View.java:14248)
  at at android.view.View.draw(View.java:15026)
  at at android.view.ViewGroup.drawChild(ViewGroup.java:3307)
  at at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3144)
  at at android.view.View.getDisplayList(View.java:14201)
  at at android.view.View.getDisplayList(View.java:14248)
  at at android.view.View.draw(View.java:15026)
  at at android.view.ViewGroup.drawChild(ViewGroup.java:3307)
  at at android.widget.ListView.drawChild(ListView.java:3403)
  at at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3144)
  at at android.widget.AbsListView.dispatchDraw(AbsListView.java:2931)
  at at android.widget.ListView.dispatchDraw(ListView.java:3398)
  at at android.view.View.draw(View.java:15315)
  at at android.widget.AbsListView.draw(AbsListView.java:5153)
  at at android.view.View.getDisplayList(View.java:14206)
  at at android.view.View.getDisplayList(View.java:14248)
  at at android.view.View.draw(View.java:15026)
  at at android.view.ViewGroup.drawChild(ViewGroup.java:3307)
  at at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3151)
  at at android.view.View.draw(View.java:15315)
  at at android.view.View.getDisplayList(View.java:14206)
  at at android.view.View.getDisplayList(View.java:14248)
  at at android.view.View.draw(View.java:15026)
  at at android.view.ViewGroup.drawChild(ViewGroup.java:3307)
  at at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3144)
  at at android.view.View.draw(View.java:15315)
  at at android.view.View.getDisplayList(View.java:14206)
  at at android.view.View.getDisplayList(View.java:14248)
  at at android.view.View.draw(View.java:15026)
  at at android.view.ViewGroup.drawChild(ViewGroup.java:3307)
  at at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3144)
  at at android.view.View.draw(View.java:15315)
  at at android.view.View.getDisplayList(View.java:14206)
  at at android.view.View.getDisplayList(View.java:14248)
  at at android.view.View.draw(View.java:15026)
  at at android.view.ViewGroup.drawChild(ViewGroup.java:3307)
  at at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3144)
  at at android.view.View.getDisplayList(View.java:14201)
  at at android.view.View.getDisplayList(View.java:14248)
  at at android.view.View.draw(View.java:15026)
  at at android.view.ViewGroup.drawChild(ViewGroup.java:3307)
  at at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3144)
  at at android.view.View.draw(View.java:15315)
  at at android.widget.FrameLayout.draw(FrameLayout.java:472)
  at at android.view.View.getDisplayList(View.java:14206)
  at at android.view.View.getDisplayList(View.java:14248)
  at at android.view.View.draw(View.java:15026)
  at at android.view.ViewGroup.drawChild(ViewGroup.java:3307)
  at at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3144)
  at at android.view.View.draw(View.java:15315)
  at at android.view.View.getDisplayList(View.java:14206)
  at at android.view.View.getDisplayList(View.java:14248)
  at at android.view.View.draw(View.java:15026)
  at at android.view.ViewGroup.drawChild(ViewGroup.java:3307)
  at at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3144)
  at at android.view.View.getDisplayList(View.java:14201)
  at at android.view.View.getDisplayList(View.java:14248)
  at at android.view.View.draw(View.java:15026)
  at at android.view.ViewGroup.drawChild(ViewGroup.java:3307)
  at at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3144)
  at at android.view.View.getDisplayList(View.java:14201)
  at at android.view.View.getDisplayList(View.java:14248)
  at at android.view.View.draw(View.java:15026)
  at at android.view.ViewGroup.drawChild(ViewGroup.java:3307)
  at at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3144)
  at at android.view.View.draw(View.java:15315)
  at at android.widget.FrameLayout.draw(FrameLayout.java:472)
  at at android.widget.ScrollView.draw(ScrollView.java:2156)
  at at md5b60ffeb829f638581ab2bb9b1a7f4f3f.ScrollViewRenderer.n_draw(Native Method)
  at at md5b60ffeb829f638581ab2bb9b1a7f4f3f.ScrollViewRenderer.draw(ScrollViewRenderer.java:59)
  at at android.view.View.getDisplayList(View.java:14206)
  at at android.view.View.getDisplayList(View.java:14248)
  at at android.view.View.draw(View.java:15026)
  at at android.view.ViewGroup.drawChild(ViewGroup.java:3307)
  at at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3151)
  at at android.view.View.draw(View.java:15315)
  at at android.view.View.getDisplayList(View.java:14206)
  at at android.view.View.getDisplayList(View.java:14248)
  at at android.view.View.draw(View.java:15026)
  at at android.view.ViewGroup.drawChild(ViewGroup.java:3307)
  at at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3144)
  at at android.view.View.getDisplayList(View.java:14201)
  at at android.view.View.getDisplayList(View.java:14248)
  at at android.view.View.draw(View.java:15026)
  at at android.view.ViewGroup.drawChild(ViewGroup.java:3307)
  at at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3144)
  at at android.view.View.draw(View.java:15315)
  at at android.view.View.getDisplayList(View.java:14206)
  at at android.view.View.getDisplayList(View.java:14248)
  at at android.view.View.draw(View.java:15026)
  at at android.view.ViewGroup.drawChild(ViewGroup.java:3307)
  at at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3144)
  at at android.view.View.getDisplayList(View.java:14201)
  at at android.view.View.getDisplayList(View.java:14248)
  at at android.view.View.draw(View.java:15026)
  at at android.view.ViewGroup.drawChild(ViewGroup.java:3307)
  at at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3144)
  at at android.view.View.draw(View.java:15315)
  at at android.support.v4.view.ViewPager.draw(ViewPager.java:2336)
  at at android.view.View.getDisplayList(View.java:14206)
  at at android.view.View.getDisplayList(View.java:14248)
  at at android.view.View.draw(View.java:15026)
  at at android.view.ViewGroup.drawChild(ViewGroup.java:3307)
  at at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3144)
  at at android.view.View.getDisplayList(View.java:14201)
  at at android.view.View.getDisplayList(View.java:14248)
  at at android.view.View.draw(View.java:15026)
  at at android.view.ViewGroup.drawChild(ViewGroup.java:3307)
  at at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3144)
  at at android.view.View.getDisplayList(View.java:14201)
  at at android.view.View.getDisplayList(View.java:14248)
  at at android.view.View.draw(View.java:15026)
  at at android.view.ViewGroup.drawChild(ViewGroup.java:3307)
  at at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3144)
  at at android.view.View.getDisplayList(View.java:14201)
  at at android.view.View.getDisplayList(View.java:14248)
  at at android.view.View.draw(View.java:15026)
  at at android.view.ViewGroup.drawChild(ViewGroup.java:3307)
  at at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3144)
  at at android.view.View.getDisplayList(View.java:14201)
  at at android.view.View.getDisplayList(View.java:14248)
  at at android.view.View.draw(View.java:15026)
  at at android.view.ViewGroup.drawChild(ViewGroup.java:3307)
  at at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3144)
  at at android.view.View.getDisplayList(View.java:14201)
  at at android.view.View.getDisplayList(View.java:14248)
  at at android.view.View.draw(View.java:15026)
  at at android.view.ViewGroup.drawChild(ViewGroup.java:3307)
  at at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3144)
  at at android.view.View.draw(View.java:15315)
  at at android.widget.FrameLayout.draw(FrameLayout.java:472)
  at at android.view.View.getDisplayList(View.java:14206)
  at at android.view.View.getDisplayList(View.java:14248)
  at at android.view.View.draw(View.java:15026)
  at at android.view.ViewGroup.drawChild(ViewGroup.java:3307)
  at at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3144)
  at at android.view.View.getDisplayList(View.java:14201)
  at at android.view.View.getDisplayList(View.java:14248)
  at at android.view.View.draw(View.java:15026)
  at at android.view.ViewGroup.drawChild(ViewGroup.java:3307)
  at at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3144)
  at at android.view.View.getDisplayList(View.java:14201)
  at at android.view.View.getDisplayList(View.java:14248)
  at at android.view.View.draw(View.java:15026)
  at at android.view.ViewGroup.drawChild(ViewGroup.java:3307)
  at at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3144)
  at at android.view.View.getDisplayList(View.java:14201)
  at at android.view.View.getDisplayList(View.java:14248)
  at at android.view.View.draw(View.java:15026)
  at at android.view.ViewGroup.drawChild(ViewGroup.java:3307)
  at at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3144)
  at at android.view.View.draw(View.java:15315)
  at at android.widget.FrameLayout.draw(FrameLayout.java:472)
  at at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:2540)
  at at android.view.View.getDisplayList(View.java:14206)
  at at android.view.View.getDisplayList(View.java:14248)
  at at android.view.HardwareRenderer$GlRenderer.buildDisplayList(HardwareRenderer.java:1570)
  at at android.view.HardwareRenderer$GlRenderer.draw(HardwareRenderer.java:1449)
  at at android.view.ViewRootImpl.draw(ViewRootImpl.java:2667)
  at at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2533)
  at at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2107)
  at at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1200)
  at at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6401)
  at at android.view.Choreographer$CallbackRecord.run(Choreographer.java:803)
  at at android.view.Choreographer.doCallbacks(Choreographer.java:603)
  at at android.view.Choreographer.doFrame(Choreographer.java:573)
  at at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:789)
  at at android.os.Handler.handleCallback(Handler.java:733)
  at at android.os.Handler.dispatchMessage(Handler.java:95)
  at at android.os.Looper.loop(Looper.java:157)
  at at android.app.ActivityThread.main(ActivityThread.java:5335)
  at at java.lang.reflect.Method.invokeNative(Native Method)
  at at java.lang.reflect.Method.invoke(Method.java:515)
  at at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
  at at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
  at at dalvik.system.NativeStart.main(Native Method)

经过对Google的一些研究后,我发现了同样的问题https://forums.xamarin.com/discussion/48144/stackoverflowerror-on-android,但在我的情况下无法应用解决方法(我无法减少itemtemplate的行数)。 但是,我不确定问题的根源是ItemTemplate中的元素数量,因为相同的ContentPage在Android上的MasterDetailPage中工作正常

如果我无法使用TabbedPage,您是否知道我可以用来在Xamarin.Forms中创建TabBar的组件/示例。

提前感谢您的帮助。 问候。 奥利弗。

1 个答案:

答案 0 :(得分:1)

当我在TabbedPage的ScrollView中包含ListView时,我遇到了同样的问题。 您需要从此布局中删除ScrollView。因为ListView有自己的内部滚动