简体   繁体   English

VS2019 更新给出 FragmentManager 错误

[英]VS2019 update gives FragmentManager error

I recently upgraded my installation of VisualStudio 2019 from 16.4.19 to 16.9.3 After cleaning up a few errors, it builds just fine.我最近将我的 VisualStudio 2019 安装从 16.4.19 升级到 16.9.3 在清理了一些错误之后,它构建得很好。 When I try to deploy and run it on a 7.0 tablet, I get the message:当我尝试在 7.0 平板电脑上部署和运行它时,我收到以下消息:

Java.Lang.IllegalStateException Message=FragmentManager has not been attached to a host.

Here is the code that generates the problem:这是产生问题的代码:

void Navigate(Android.Support.V4.App.Fragment fragment)
{
    var transaction = base.SupportFragmentManager.BeginTransaction();
    transaction.Replace(Resource.Id.contentFrame, fragment);
    transaction.Commit();
}

And this code calls it:这段代码称之为:

void OnMenuItemSelected(object sender, Android.Support.Design.Widget.NavigationView.NavigationItemSelectedEventArgs e)
{
    Vars.OnMain = false;    //turn off screen updates until mainscreen is open
    switch (e.MenuItem.ItemId)
    {
        case Resource.Id.aboutMenuItem: Navigate(new AboutFragment()); break;
        case Resource.Id.catalogMenuItem: Navigate(new CatalogFragment()); break;
        //case Resource.Id.itemMenuItem: Navigate(new ItemFragment()); break;
        case Resource.Id.helpMenuItem: Navigate(new HelpFragment()); break;
        case Resource.Id.settingsMenuItem: Navigate(new SettingsFragment()); break;
        case Resource.Id.coordinateMenuItem: Navigate(new CoordinateFragment()); break;
        case Resource.Id.mainMenuItem: Navigate(new MainScreenFragment()); break;
        default: return;
    }

    e.MenuItem.SetChecked(true);

    //var drawerLayout = FindViewById<Android.Support.V4.Widget.DrawerLayout>(Resource.Id.drawerLayout);
    drawerLayout.CloseDrawer(Android.Support.V4.View.GravityCompat.End);
}

The App has been running for years and is too large to post here.该应用程序已经运行多年,并且太大,无法在此处发布。

Has something changed in the VS2019 environment during the last year that would cause this problem?去年 VS2019 环境中是否发生了会导致此问题的变化?

Thanks for your help, Dan谢谢你的帮助,丹

From the following code you posted,we found that you're getting the fragment manager from the base variable.从您发布的以下代码中,我们发现您正在从base变量中获取片段管理器。 Where does base itself get the FragmentManager ? base 本身在哪里获得FragmentManager When you Navigate , the activity maybe been destroyed and recreated.当您Navigate时,活动可能已被销毁并重新创建。 Therefore, you might need to get a new FragmentManager.因此,您可能需要获取一个新的 FragmentManager。

void Navigate(Android.Support.V4.App.Fragment fragment)
{
    var transaction = base.SupportFragmentManager.BeginTransaction();
    transaction.Replace(Resource.Id.contentFrame, fragment);
    transaction.Commit();
}

So, you can try to use the following code:因此,您可以尝试使用以下代码:

FragmentTransaction transaction = FragmentManager.BeginTransaction ();
transaction.Replace(Resource.Id.contentFrame, fragment);
transaction.Commit();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 vs2019 - Xamarin:丢失“Java Development Kit Location”的路径设置 - vs2019 - Xamarin: loses path settings of "Java Development Kit Location" FragmentManager 从活动到片段的错误 - Error in FragmentManager from activity to fragment FragmentManager的FragmentStatePageAdapter错误(使用ViewPager处理) - FragmentStatePageAdapter error with FragmentManager (dealing with ViewPager) Android:fragmentManager出现问题(错误XML inflateExeption) - Android:Having problems with fragmentManager(Error XML inflateExeption) 无法解决 fragmentmanager Android 中的方法 super() 错误 - Cannot resolve method super() error in fragmentmanager Android 错误:构造函数MainActivity.ScreenSlidePagerAdapter(FragmentManager)未定义 - Error: The constructor MainActivity.ScreenSlidePagerAdapter(FragmentManager) is undefined 错误不兼容类型:android.app.FragmentManager无法转换为android.support.v4.app.FragmentManager - Error incompatible types: android.app.FragmentManager cannot be converted to android.support.v4.app.FragmentManager 错误:必需:android:support.v4.FragmentManager,找到:android.app.FragmentManager - Error: required: android:support.v4.FragmentManager, found: android.app.FragmentManager FragmentManager尝试查找项目的旧包名称,并给出“找不到片段的视图” - FragmentManager tries to find the old package name of the project and gives “No view found for fragment” FragmentManager回收 - FragmentManager recycled
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM