我在生產中有一個Xamarin Android應用程序。在谷歌播放控制檯,我可以看到許多同樣的崩潰的實例,但我無法在本地重現它。堆棧跟蹤是很普通:如何從生產堆棧跟蹤中找到崩潰原因
java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
... 1 more
Caused by: md52ce486a14f4bcd95899665e9d932190b.JavaProxyThrowable: System.NullReferenceException: Object reference not set to an instance of an object
at MyApp.Activities.MainActivity.OnCreate (Android.OS.Bundle) <0x001a4>
at Android.App.Activity.n_OnCreate_Landroid_os_Bundle_ (intptr,intptr,intptr) <0x0005b>
at (wrapper dynamic-method) object.2b42a88f-c445-435d-aa7c-f905596cf5db (intptr,intptr,intptr) <0x00043>
at md5317d85657469e27a0cec50bfaa82e3ea.MainActivity.n_onCreate(Native Method)
at md5317d85657469e27a0cec50bfaa82e3ea.MainActivity.onCreate(MainActivity.java:43)
at android.app.Activity.performCreate(Activity.java:6221)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2611)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2723)
at android.app.ActivityThread.access$900(ActivityThread.java:172)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1422)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5832)
... 4 more
所以我能看到飛機墜毀在我MainActivity
的OnCreate
。但是哪裏?
崩潰是可能的在某種方法從OnCreate調用並且堆棧跟蹤不準確?因爲我的OnCreate非常簡單,只是調用其他方法,該方法本身的代碼非常幾行:
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
#if DEBUG_FRAGMENTS
FragmentManager.EnableDebugLogging(true);
#endif
var userSettingsManager = new UserSettingsManager(this);
Window.SetFlags(userSettingsManager.FullScreen ? WindowManagerFlags.Fullscreen : 0, WindowManagerFlags.Fullscreen);
SetContentView(Resource.Layout.MainLayout);
if ((int)Build.VERSION.SdkInt >= 17 && Window.DecorView != null)
{
Window.DecorView.LayoutDirection = Utils.LocalizationHelper.IsLanguageRTL(userSettingsManager.Language) ? Android.Views.LayoutDirection.Rtl : Android.Views.LayoutDirection.Ltr;
}
if (this.ActionBar != null)
{
this.ActionBar.Hide();
}
InitializeSomething(userSettingsManager);
InitializeSomethingElse();
InitializeStuff();
}
什麼是該行的末尾數
at MyApp.Activities.MainActivity.OnCreate (Android.OS.Bundle) <0x001a4>
可它在某種程度上幫我找到空引用的確切線?在常見的.NET錯誤中有IL偏移量,但這似乎不是一個。
在API 22處從Samsung Galaxy Tab獲取相同的堆棧跟蹤,此時應用程序在後臺運行一段時間,然後再次顯示。我們有代碼攔截這種行爲,但崩潰發生在MainActivity.OnCreate之前 - 我的第一行有日誌輸出,而我沒有看到它。日誌顯示應用程序是正確的SaveInstance-d並在之前被殺死,但有些事情仍然是錯誤的。 –