我在 MVVMCross 中使用 LegacyBar https://github.com/Cheesebaron/LegacyBar和MvxDialogActivity
我有一个 LegacyBar 示例,如下所示:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res/TestAndroid"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<legacybar.library.bar.LegacyBar
android:id="@+id/actionbar"
style="@style/actionbar"
/>
<ListView android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
和代码:
[Activity(Label = "TestAndroid", MainLauncher = true, Icon = "@drawable/icon")]
public class Activity1 : Activity
{
int count = 1;
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.Main);
var legacyBar = FindViewById<LegacyBar.Library.Bar.LegacyBar>(Resource.Id.actionbar);
legacyBar.SetDropDown(this, new string[] { "My First Account", "My Second Account", "My Third Account" }, DropDownSelected);
}
private void DropDownSelected(object sender, AdapterView.ItemSelectedEventArgs args)
{
RunOnUiThread(() => Toast.MakeText(this, "You selected account: " + args.Position, ToastLength.Short).Show());
}
}
我运行正常,然后添加对 MvvmCross 的引用,然后创建另一个视图
public class TestDialogView : MvxDialogActivity
{
}
我按 F5 运行应用程序,出现以下错误enter code here
:
未处理的异常:07-31 01:30:53.752 E/mono(1526):System.Reflection.TargetInvocationException:调用目标已引发异常。---> System.TypeInitializationException:Drawable 的类型初始化程序引发了异常 ---> System.NullReferenceException:对象引用未设置为对象的实例 07-31 01:30:53.752 E/mono(1526) : 在 Android.Runtime.ResourceIdManager.m_[错误] 致命的未处理异常:System.Reflection.TargetInvocationException:调用目标已引发异常。---> System.TypeInitializationException:Drawable 的类型初始化程序引发了异常---> System.NullReferenceException:对象引用未设置为对象的实例 07-31 01:30:53.762 I/mono(1526) : 在 Android.Runtime.ResourceIdManager.m_D1 (System.Reflection.Assembly ass) [0x0000d] 在 /Users/builder/data/lanes/monodroid-lion-bigsplash/0e0e51f9/source/monodroid/src/Mono.Android/src/Runtime/ResourceIdManager.cs:21 07 -31 01:30:53.762 I/mono (1526): 在 /Users/builder/data/lanes/monodroid-lion-bigsplash/0e0e51f9/source/monodroid/src 中的 Android.Runtime.ResourceIdManager.UpdateIdValues () [0x0003a] /Mono.Android/src/Runtime/ResourceIdManager.cs:22 07-31 01:30:53.762 I/mono (1526): 在 Cirrious.MvvmCross.Dialog.Droid.Resource+Drawable..cctor () [0x00000] 中:0 07-31 01:30:53.762 I/mono (1526):---内部异常堆栈跟踪结束---07-31 01:30:53.762 I/mono (1526):在 [ProjectName].Resource .UpdateIdValues () [0x00001] 在 c:\DATA\Working\Rabiti[ProjectName]-MonoDroid[ProjectName]\
有人有什么建议吗?
谢谢!