Xamarin .aar绑定:从库类的意图启动一个活动导致setImageResource上的NullPointerException

时间:2018-04-18 18:42:52

标签: android xamarin binding

我花了太长时间试图解决这个问题。这是我的第一个Xamarin应用程序,我真的可以在这个上使用一些帮助。

我从Xamarin Forms的.aar库开始一个活动:

var intent = WPAPIAuthentication.MakeLoginIntent(Android.App.Application.Context.ApplicationContext);
intent.AddFlags(Android.Content.ActivityFlags.NewTask);
Android.App.Application.Context.ApplicationContext.StartActivity(intent);

这适用于并显示LoginActivity。然后,此活动在用户登录后启动第二个库活动,从而导致以下内容:

java.lang.RuntimeException: Unable to start activity ComponentInfo{org.fakeurl.MyApp/com.company.android.library.springboard.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ImageView.setImageResource(int)' on a null object reference
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2778)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
    at android.app.ActivityThread.-wrap11(Unknown Source:0)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loop(Looper.java:164)
    at android.app.ActivityThread.main(ActivityThread.java:6494)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ImageView.setImageResource(int)' on a null object reference
    at com.company.android.library.springboard.MainActivity.c(MainActivity.java:303)
    at com.company.android.library.customactivities.MyFolderActivity.C(MyFolderActivity.java:382)
    at com.company.android.library.customactivities.PostLoginMyFolderActivity.onStart(PostLoginMyFolderActivity.java:179)
    at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1334)
    at android.app.Activity.performStart(Activity.java:7019)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2741)

我测试了Android Studio中的所有内容,它按预期工作。

0 个答案:

没有答案