关于在MvvmCross中膨胀Spinner的NullPointerException导致应用程序在Android 4.4上崩溃

时间:2013-11-25 15:08:46

标签: android xamarin mvvmcross

在Android 4.4上显示包含MvxSpinner的片段时,该片段绑定到包含元素的集合(List或ObservableCollection),抛出NullPointer。

如果集合为空,则不会抛出异常。

相同的代码适用于Android 4.3,没有任何问题。

堆栈跟踪与Android app crashes with NullPointerException in ChoreoGrapherWeird NullPointerException in Spinner中的跟踪相同,但建议的修复无效。

片段在取自Cheesebaron的FragmentPagerAdapter中管理。

这是Xamarin,MvvmCross,Android还是pebcak问题?

片段:

public class XFragment : MvxFragment
{
    public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
    {
        OnCreateViewCalled += async (sender, args) =>
        {
            await ((IXViewModel)ViewModel).InitializeViewModelAsync();
        };
        var ignore = base.OnCreateView(inflater, container, savedInstanceState);

        return this.BindingInflate(Resource.Layout.CreateCustomerProduct, null);
    }
}

查看:

<MvxSpinner
                style="@style/formSpinner"
                android:id="@+id/MyComponent.spinnerX"
                android:prompt="@string/XPrompt"
                local:MvxBind="ItemsSource Xes; SelectedItem MyModel.X.Bouquet" />

堆栈追踪:

11-25 11:11:23.425 D/AndroidRuntime(20978): Shutting down VM
11-25 11:11:23.425 W/dalvikvm(20978): threadid=1: thread exiting with uncaught exception (group=0x41851b90)
11-25 11:11:23.455 E/AndroidRuntime(20978): FATAL EXCEPTION: main
11-25 11:11:23.455 E/AndroidRuntime(20978): Process: FSIA.Android, PID: 20978
11-25 11:11:23.455 E/AndroidRuntime(20978): java.lang.NullPointerException
11-25 11:11:23.455 E/AndroidRuntime(20978):     at android.widget.TextView.makeNewLayout(TextView.java:6124)
11-25 11:11:23.455 E/AndroidRuntime(20978):     at android.widget.TextView.onMeasure(TextView.java:6400)
11-25 11:11:23.455 E/AndroidRuntime(20978):     at android.view.View.measure(View.java:16458)
11-25 11:11:23.455 E/AndroidRuntime(20978):     at android.widget.Spinner.setUpChild(Spinner.java:632)
11-25 11:11:23.455 E/AndroidRuntime(20978):     at android.widget.Spinner.makeView(Spinner.java:595)
11-25 11:11:23.455 E/AndroidRuntime(20978):     at android.widget.Spinner.getBaseline(Spinner.java:431)
11-25 11:11:23.455 E/AndroidRuntime(20978):     at android.widget.LinearLayout.measureHorizontal(LinearLayout.java:1262)
11-25 11:11:23.455 E/AndroidRuntime(20978):     at android.widget.LinearLayout.onMeasure(LinearLayout.java:590)
11-25 11:11:23.455 E/AndroidRuntime(20978):     at android.view.View.measure(View.java:16458)
11-25 11:11:23.455 E/AndroidRuntime(20978):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
11-25 11:11:23.455 E/AndroidRuntime(20978):     at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404)
11-25 11:11:23.455 E/AndroidRuntime(20978):     at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
11-25 11:11:23.455 E/AndroidRuntime(20978):     at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
11-25 11:11:23.455 E/AndroidRuntime(20978):     at android.view.View.measure(View.java:16458)
11-25 11:11:23.455 E/AndroidRuntime(20978):     at android.widget.ScrollView.measureChildWithMargins(ScrollView.java:1226)
11-25 11:11:23.455 E/AndroidRuntime(20978):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
11-25 11:11:23.455 E/AndroidRuntime(20978):     at android.widget.ScrollView.onMeasure(ScrollView.java:326)
11-25 11:11:23.455 E/AndroidRuntime(20978):     at android.view.View.measure(View.java:16458)
11-25 11:11:23.455 E/AndroidRuntime(20978):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
11-25 11:11:23.455 E/AndroidRuntime(20978):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
11-25 11:11:23.455 E/AndroidRuntime(20978):     at android.view.View.measure(View.java:16458)
11-25 11:11:23.455 E/AndroidRuntime(20978):     at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1447)
11-25 11:11:23.455 E/AndroidRuntime(20978):     at android.view.View.measure(View.java:16458)
11-25 11:11:23.455 E/AndroidRuntime(20978):     at android.widget.LinearLayout.measureVertical(LinearLayout.java:847)
11-25 11:11:23.455 E/AndroidRuntime(20978):     at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
11-25 11:11:23.455 E/AndroidRuntime(20978):     at android.view.View.measure(View.java:16458)
11-25 11:11:23.455 E/AndroidRuntime(20978):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
11-25 11:11:23.455 E/AndroidRuntime(20978):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
11-25 11:11:23.455 E/AndroidRuntime(20978):     at android.view.View.measure(View.java:16458)
11-25 11:11:23.455 E/AndroidRuntime(20978):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
11-25 11:11:23.455 E/AndroidRuntime(20978):     at com.android.internal.widget.ActionBarOverlayLayout.onMeasure(ActionBarOverlayLayout.java:327)
11-25 11:11:23.455 E/AndroidRuntime(20978):     at android.view.View.measure(View.java:16458)
11-25 11:11:23.455 E/AndroidRuntime(20978):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
11-25 11:11:23.455 E/AndroidRuntime(20978):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
11-25 11:11:23.455 E/AndroidRuntime(20978):     at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2289)
11-25 11:11:23.455 E/AndroidRuntime(20978):     at android.view.View.measure(View.java:16458)
11-25 11:11:23.455 E/AndroidRuntime(20978):     at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1914)
11-25 11:11:23.455 E/AndroidRuntime(20978):     at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1111)
11-25 11:11:23.455 E/AndroidRuntime(20978):     at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1293)
11-25 11:11:23.455 E/AndroidRuntime(20978):     at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:998)
11-25 11:11:23.455 E/AndroidRuntime(20978):     at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5582)
11-25 11:11:23.455 E/AndroidRuntime(20978):     at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
11-25 11:11:23.455 E/AndroidRuntime(20978):     at android.view.Choreographer.doCallbacks(Choreographer.java:562)
11-25 11:11:23.455 E/AndroidRuntime(20978):     at android.view.Choreographer.doFrame(Choreographer.java:532)
11-25 11:11:23.455 E/AndroidRuntime(20978):     at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
11-25 11:11:23.455 E/AndroidRuntime(20978):     at android.os.Handler.handleCallback(Handler.java:733)
11-25 11:11:23.455 E/AndroidRuntime(20978):     at android.os.Handler.dispatchMessage(Handler.java:95)
11-25 11:11:23.455 E/AndroidRuntime(20978):     at android.os.Looper.loop(Looper.java:137)
11-25 11:11:23.455 E/AndroidRuntime(20978):     at android.app.ActivityThread.main(ActivityThread.java:4998)
11-25 11:11:23.455 E/AndroidRuntime(20978):     at java.lang.reflect.Method.invokeNative(Native Method)
11-25 11:11:23.455 E/AndroidRuntime(20978):     at java.lang.reflect.Method.invoke(Method.java:515)
11-25 11:11:23.455 E/AndroidRuntime(20978):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777)
11-25 11:11:23.455 E/AndroidRuntime(20978):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:593)
11-25 11:11:23.455 E/AndroidRuntime(20978):     at dalvik.system.NativeStart.main(Native Method)

1 个答案:

答案 0 :(得分:0)

根据https://github.com/MvvmCross/MvvmCross/issues/507,此问题已在3.1.1

中修复