c# - System.NotSupportedException : Unable to find the default constructor. 请提供缺少的构造函数 (xamarin C#)

标签 c# android xamarin xamarin.android

我有一个 Activity ,它实际上调用一个 fragment 来在 recyclerView 中显示其内容。问题是,在某些 Activity 中,当屏幕旋转发生变化时,它会再次调用实际上是正确的 OnCreate。但我不知道为什么 base.OnCreate(savedInstanceState);正如标题所示,给了我错误。在具有相同功能的其他 Activity 上进展顺利。 3/6 Activity 无法响应屏幕旋转。有相关知识吗?

    protected override void OnCreate(Bundle savedInstanceState)
    {
        base.OnCreate(savedInstanceState); // error occurred here

        SetContentView(Resource.Layout.mylayout);
        //rest of codes
    }

    //rest of the codes are removed due to error is only on this part

最佳答案

解决方案:

当使用用户定义的构造函数创建 fragment 时,即使内部没有任何内容,也应该手动提供默认构造函数。

我发现问题不存在于base.OnCreate 中,而是存在于我创建的 fragment 中。我使用构造函数创建了一个 fragment ,但没有提供默认构造函数,因为如果您创建任何类型的构造函数,则应该手动编码。

我刚刚为其创建了一个默认构造函数,它解决了问题。

关于c# - System.NotSupportedException : Unable to find the default constructor. 请提供缺少的构造函数 (xamarin C#),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43865608/

相关文章:

c# - 为什么我在 azure 应用程序服务中从表单发布时收到 404 错误,但它在 localhost 中运行良好

c# - 如何从 id 数组中获取一组行?

Android、msm_pcm_out 设备和 ALSA 库

c# - 通过点击手势导航到 xamarin 表单中的下一页

c# - 统一DI。通用类型注册和 IsRegistered 方法

c# - 使用不带参数的 Split 和 RemoveEmptyEntries 选项之间的区别

java - 蓝牙应用程序无法在 Lollipop 上运行的设备上运行

java - 为什么 OSX 无法检测到 android Galaxy S 进行 USB 调试?

ios - Xamarin 表格 : Navigation popping without animation on iOS

c# - xamarin 绑定(bind) objective-c 库