我有一个 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/