Xamarin android代码在使用以下代码时会产生运行时异常:
public class MyActivity: global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
protected override void OnCreate(Bundle bundle)
{
ToolbarResource = Resource.Layout.toolbar;
TabLayoutResource = Resource.Layout.tabs;
base.OnCreate(bundle);
global::Xamarin.Forms.Forms.Init(this, bundle);
LoadApplication(new App());
}
}
运行应用程序时,它的构建成功。但在运行时,iot会遇到以下错误:StackTrace:
Java.Lang.IllegalStateException: Exception of type 'Java.Lang.IllegalStateException' was thrown.
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () <IL 0x00011, 0x00078>
at Android.Runtime.JNIEnv.CallIntMethod (intptr,intptr) <IL 0x00069, 0x00297>
at Android.Support.V4.App.FragmentTransactionInvoker.Commit () <IL 0x00038, 0x00143>
at Xamarin.Forms.Platform.Android.AppCompat.NavigationPageRenderer.SwitchContentAsync (Xamarin.Forms.Page,bool,bool,bool) <IL 0x00140, 0x00953>
at Xamarin.Forms.Platform.Android.AppCompat.NavigationPageRenderer.OnPushAsync (Xamarin.Forms.Page,bool) <IL 0x00005, 0x00063>
at Xamarin.Forms.Platform.Android.AppCompat.NavigationPageRenderer.PushViewAsync (Xamarin.Forms.Page,bool) <IL 0x00003, 0x00053>
at Xamarin.Forms.Platform.Android.AppCompat.NavigationPageRenderer.<OnElementChanged>b__13_0 (Xamarin.Forms.Page) <IL 0x00003, 0x0004f>
at Xamarin.Forms.EnumerableExtensions.ForEach<Xamarin.Forms.Page> (System.Collections.Generic.IEnumerable`1<Xamarin.Forms.Page>,System.Action`1<Xamarin.Forms.Page>) <0x00157>
An unhandled exception occured.
at Xamarin.Forms.Platform.Android.AppCompat.NavigationPageRenderer.OnElementChanged (Xamarin.Forms.Platform.Android.ElementChangedEventArgs`1<Xamarin.Forms.NavigationPage>) <IL 0x001bb, 0x00e0f>
at Xamarin.Forms.Platform.Android.VisualElementRenderer`1<Xamarin.Forms.NavigationPage>.SetElement (Xamarin.Forms.NavigationPage) <0x00827>
at Xamarin.Forms.Platform.Android.VisualElementRenderer`1<Xamarin.Forms.NavigationPage>.Xamarin.Forms.Platform.Android.IVisualElementRenderer.SetElement (Xamarin.Forms.VisualElement) <0x0012b>
at Xamarin.Forms.Platform.Android.Platform.CreateRenderer (Xamarin.Forms.VisualElement) <IL 0x00021, 0x0014f>
at Xamarin.Forms.Platform.Android.MasterDetailContainer.set_ChildView (Xamarin.Forms.VisualElement) <IL 0x00049, 0x001df>
at Xamarin.Forms.Platform.Android.AppCompat.MasterDetailPageRenderer.UpdateDetail () <IL 0x0001d, 0x000e3>
at Xamarin.Forms.Platform.Android.AppCompat.MasterDetailPageRenderer.HandlePropertyChanged (object,System.ComponentModel.PropertyChangedEventArgs) <IL 0x0002c, 0x00157>
at (wrapper delegate-invoke) <Module>.invoke_void_object_PropertyChangedEventArgs (object,System.ComponentModel.PropertyChangedEventArgs) <IL 0x0002f, 0x0008b>
at Xamarin.Forms.BindableObject.OnPropertyChanged (string) <IL 0x00012, 0x000d7>
at Xamarin.Forms.Element.OnPropertyChanged (string) <IL 0x00002, 0x0005f>
at Xamarin.Forms.MasterDetailPage.set_Detail (Xamarin.Forms.Page) <IL 0x0007b, 0x002eb>
at eWorker.App.SetRootPage (Xamarin.Forms.Page) [0x00025] in C:\SIProducts\360\Dev\Frontend\BugFixes\Source\BIF\Source\eWorker\XamarinApp\Shared\eWorkerShared\App.cs:97
at eWorker.Views.HomePage.OnAppearing () [0x0000e] in C:\SIProducts\360\Dev\Frontend\BugFixes\Source\BIF\Source\eWorker\XamarinApp\Shared\eWorkerShared\Views\HomePage.cs:39
at Xamarin.Forms.Page.SendAppearing () <IL 0x00025, 0x0011f>
at Xamarin.Forms.Platform.Android.AppCompat.FragmentContainer.set_UserVisibleHint (bool) <IL 0x0004b, 0x002a3>
at Xamarin.Forms.Platform.Android.AppCompat.NavigationPageRenderer/<>c__DisplayClass52_0.<SwitchContentAsync>b__1 () <IL 0x00014, 0x0008f>
at Xamarin.Forms.Forms/AndroidPlatformServices/<>c__DisplayClass17_0.<StartTimer>b__1 () <IL 0x00006, 0x00053>
at Java.Lang.Thread/RunnableImplementor.Run () <IL 0x00011, 0x00097>
at Java.Lang.IRunnableInvoker.n_Run (intptr,intptr) <IL 0x0000a, 0x000a3>
at (wrapper dynamic-method) object.ba4e6bb4-0814-4b71-9867-78bee59c6f1f (intptr,intptr) <IL 0x00011, 0x0003b>
--- End of managed exception stack trace ---
java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState
at android.support.v4.app.FragmentManagerImpl.checkStateLoss(FragmentManager.java:1448)
at android.support.v4.app.FragmentManagerImpl.enqueueAction(FragmentManager.java:1466)
at android.support.v4.app.BackStackRecord.commitInternal(BackStackRecord.java:634)
at android.support.v4.app.BackStackRecord.commit(BackStackRecord.java:613)
at mono.java.lang.RunnableImplementor.n_run(Native Method)
at mono.java.lang.RunnableImplementor.run(RunnableImplementor.java:29)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5603)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
at dalvik.system.NativeStart.main(Native Method)
03): Shutting down VM
hreadid=1: thread exiting with uncaught exception (group=0x41b6bc08)
此错误发生在调用Navigation.PushAsync
或Navigation.PushModalAsync
的位置。
答案 0 :(得分:0)
在一些R&amp; D之后,我发现问题在于它保存了上一阶段的App。当手动删除旧应用程序然后在调试时安装应用程序时,它可以工作。
但这不是一个合适的解决方案,所以欢迎任何建议/帮助。