首页 > 解决方案 > 导航到其他视图时如何解决活动未找到异常?

问题描述

我得到一个 Android.Content.ActivityNotFoundException: 当我想去另一个活动时。此外,每次我想查看我的应用程序时,我都必须重新创建我的模拟器,因为它在我第二次启动模拟器时总是会导致 adb 错误。

我读到这可能是由另一个异常引起的,但是我检查了另一个代码,但没有找到任何东西

Button btnentrar = FindViewById<Button>(Resource.Id.createlist);

        btnentrar.Click += delegate
        {
            StartActivity(typeof(listeditorclass));
        };

//活动:

    private List<string> mItems;
    private ListView mListView;

    protected override void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);

        SetContentView(Resource.Layout.listeditor);
        mListView = FindViewById<ListView>(Resource.Id.listView);

        mItems = new List<string>();
        mItems.Add("Milch");
        mItems.Add("Brot");
        mItems.Add("Apfel");

        MyListViewAdapter adapter = new MyListViewAdapter(this, mItems);

        mListView.Adapter = adapter;}

我也不知道 AppCompatActivity 和正常活动之间的区别。所以一般用户在单击按钮时应该会看到带有我的列表的新视图(创建列表)。

标签: xamarin.android

解决方案


我以前没有在 Xamarin 上使用过匿名代表,这是一件很酷的事情。尝试使用意图并传递Context

    btnentrar.Click += delegate
    {
        StartActivity(new Intent(this, typeof(listeditorclass)));
    };

推荐阅读