【发布时间】:2014-02-05 20:32:28
【问题描述】:
我的一些用户遇到了崩溃,这是在 Google Play 开发者控制台的崩溃报告中显示的错误:
Unable to start activity ComponentInfo{com.havens1515.autorespond/com.havens1515.autorespond.SettingsMenuNew}: android.app.Fragment$InstantiationException: Unable to instantiate fragment com.havens1515.autorespond.NotificationOptions: make sure class name exists, is public, and has an empty constructor that is public
用户说这是在打开SettingsMenuNew 内的任何设置菜单时发生的,上面的错误中提到了,但我的手机没有遇到崩溃。 SettingsMenuNew 是 PreferenceActivity,所有子菜单都是 PreferenceFragment
每个PreferenceFragment 都有一个空构造函数,我不知道还有什么问题。我还在其他人的问题中看到它需要 newInstance 方法,但如果我不将任何其他参数放入片段中,我认为我真的不需要它。
这里是一些显示这些方法的代码:
public class NotificationOptions extends PreferenceFragment
{
public NotificationOptions()
{
}
public static NotificationOptions newInstance(int title, String message)
{
NotificationOptions f = new NotificationOptions();
return f;
}
...
}
【问题讨论】:
-
如果 NotificationOptions 是一个内部类,它应该是静态的。
-
它不是内部类,它在自己的文件中
-
可能你忘了把它添加到proguard异常或者使用了错误的proguard配置。
-
这可能是问题所在。我会调查一下。我不太了解 proguard 的工作原理,所以我可能需要做一些研究。
-
我也有类似的问题,不过是在国外手机上。我注意到有些人选中了开发者选项“不保留活动”,这会导致应用在返回主活动时崩溃。
标签: java android android-fragments preferenceactivity