简体   繁体   English

无法通过嵌套类型X访问外部类型X的非静态成员

[英]Cannot access a non-static member of outer type X via nested type X

I want to call a method in the Main Activity to call a new Fragment using 我想调用Main Activity中的方法来调用一个新的Fragment
((FragmentActivity)Activity).ShowFragment(new SmokeSensor()); ((FragmentActivity)Activity).ShowFragment(new SmokeSensor());

however it throws the error: 但它会抛出错误:

Cannot access a non-static member of outer type 无法访问外部类型的非静态成员

'Android.Support.V4.App.Fragment' via nested type 'Android.Support.V4.App.Fragment'通过嵌套类型

'*******.Fragments.Dashboard.ViewAdapter` “*******。Fragments.Dashboard.ViewAdapter`

What am I doing wrong? 我究竟做错了什么?

Code: 码:

public void ShowFragment(SupportFragment fragment) {
    var transaction = SupportFragmentManager.BeginTransaction();
    connectionStatus.Visibility = ViewStates.Gone;

    if (!ConnectionDetector.IsConnected(this)) {
        connectionStatus.Visibility = ViewStates.Visible;

        transaction.Detach(currentFragment);
        transaction.Commit();
        drawerLayout.CloseDrawer(leftDrawer);

        return;
    }

    if (fragment == currentFragment) {
        transaction.Detach(currentFragment);
        transaction.Attach(currentFragment);
        transaction.Commit();
        drawerLayout.CloseDrawer(leftDrawer);

        return;
    }

    transaction.SetCustomAnimations(Resource.Animation.slide_in,
                                    Resource.Animation.slide_out);
    transaction.Replace(Resource.Id.fragment_container, fragment);
    transaction.Commit();
    drawerLayout.CloseDrawer(leftDrawer);
    currentFragment = fragment;
}

why you'r "Android.Support.V4.App.Fragment" can be only static in *******.Fragments.Dashboard.ViewAdapter ? 为什么你的“Android.Support.V4.App.Fragment”在*******中只能是静态的.Fragments.Dashboard.ViewAdapter?

see that cannot-access-a-non-static-member-of-outer-type or this 看到无法访问非静态成员的外部类型 类型

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

相关问题 无法通过嵌套类型访问外部类型的非静态成员 - Cannot access a non-static member of outer type via nested type 无法通过嵌套类型“FormMain.ImageDelegateClass”访问外部类型“FormMain”的非静态成员 - Cannot access a non-static member of outer type 'FormMain' via nested type 'FormMain.ImageDelegateClass' 无法使用第三方提供的类通过嵌套类型访问外部类型XXX的非静态成员 - Cannot access a non-static member of outer type XXX via nested type with a third-party provided class C#无法访问外部类型的非静态成员 - C# cannot access a non-static member of outer type 无法访问外部类型的非静态成员 - Cannot access a non-static member of outer type 使标签静态错误:无法通过嵌套类型“windowsForm8.Form1.DBConnect”访问外部类型“windowsForm8.Form1”的非静态成员 - make a label static error : cannot access a non-static member of outer type 'windowsForm8.Form1' via nested Type 'windowsForm8.Form1.DBConnect' 无法通过嵌套类型访问外部类型的非静态成员 - Cannot access a nonstatic member of outer type… via nested type 非静态表达 <Func<X> &gt;访问&#39;this&#39; - Non-static Expression<Func<X>> with access to 'this' 嵌套类:无法访问静态上下文中的非静态字段 - Nested class: Cannot access non-static field in static context 无法访问外部类型的非静态成员 - Cannot access a nonstatic member of outer type
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM