对话框首选项 - 错误
我正在尝试创建一个对话框首选项,如下所示
<DialogPreference
android:key="cachePref"
android:dialogMessage="Testing message"
android:dialogTitle="Title Test"
android:positiveButtonText="positive"
android:summary="Clear images save to disk"
android:title="Clear Image Cache" />
但是当活动运行时,它会强制关闭并出现以下错误
11-01 01:21:18.820: E/AndroidRuntime(19644): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.bakasura/com.bakasura.SettingsPreferences}: android.view.InflateException: Binary XML file line #71: Error inflating class java.lang.reflect.Constructor
I am trying to create a dialog preference as follows
<DialogPreference
android:key="cachePref"
android:dialogMessage="Testing message"
android:dialogTitle="Title Test"
android:positiveButtonText="positive"
android:summary="Clear images save to disk"
android:title="Clear Image Cache" />
But when the activity runs it force closes with the following error
11-01 01:21:18.820: E/AndroidRuntime(19644): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.bakasura/com.bakasura.SettingsPreferences}: android.view.InflateException: Binary XML file line #71: Error inflating class java.lang.reflect.Constructor
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这看起来像Android 问题 3972:使用 DialogPreference 时出现 InstantiationException:
DialogPreference
始终是一个抽象类,因此它不应该能够被实例化——但是反射代码中的一个错误允许在Android 1.6之前这样做。之后,它正确地抛出异常。解决方法是创建一个扩展
DialogPreference
的自定义类,并将其用作 在问题的评论 9 中建议。This looks like Android Issue 3972: InstantiationException when using DialogPreference:
DialogPreference
always was an abstract class and as such it should not have been able to be instantiated -- but a bug in reflection code allowed to do so anyway up to Android 1.6. After that, it correctly throws an exception.A work around is to create a custom class extending
DialogPreference
and use that instead as suggested in comment 9 of the issue.