Android在XML ClassNotFound中膨胀自定义视图错误

Android在XML ClassNotFound中膨胀自定义视图错误,android,android-layout,android-preferences,android-xml,dialog-preference,Android,Android Layout,Android Preferences,Android Xml,Dialog Preference,我的XML代码有一些问题,希望您能帮我解决 我在这个包中有这个类: package com.example.myview public class CustomDialog extends DialogPreference { public CustomDialog(Context context, AttributeSet attrs) { super(context, attrs); // TODO Auto-generated construct

我的XML代码有一些问题,希望您能帮我解决

我在这个包中有这个类:

package com.example.myview

public class CustomDialog extends DialogPreference {

    public CustomDialog(Context context, AttributeSet attrs) {
        super(context, attrs);
        // TODO Auto-generated constructor stub
    }

    public CustomDialog(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        // TODO Auto-generated constructor stub
    }
}
然后我有一个首选项xml文件:

<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >

    <com.example.myview.CustomDialog
        android:dialogMessage="Are you sure you wish delete you account"
        android:key="deleteAccountPreference"
        android:negativeButtonText="Cancel"
        android:positiveButtonText="Okay"
        android:summary="@string/preferences_deleteaccount_summary"
        android:title="@string/preferences_deleteaccount_title" />

</PreferenceScreen>
为了总结我的问题,我想知道如何更改xml文件所查看的路径,或者找出为什么它不能膨胀我的自定义视图。


提前感谢:)

我遇到了与您上面提到的基本相同的问题。我假设您尝试在图形布局和首选xml文件的xml视图之间来回切换,对吗? 下面是我克服初始化问题的廉价方法(应该类似于ClassNotFoundException问题):

  • 复制一个在xml中类似引用的现有类(在xml中有类似com…ClassName…的内容,并将“ClassName”重命名为CustomDialog(在您的特定情况下)
  • 在这样做之后,我仍然得到一个“未找到类”错误-我刚刚重建了整个项目,这个错误消失了。我新创建的小部件在图形布局中相应地呈现出来
  • 我还没有看到我是否遇到了你所做的膨胀错误,但我希望我的回答仍然能有所帮助。如果没有,很抱歉,这实际上是我在stackoverflow上的第一篇文章,而且我承认我在Android上是n00b。边学习边学习:)

    03-16 17:03:18.032: E/AndroidRuntime(20224): android.view.InflateException: Binary XML file line #4: Error inflating class com.example.myview.CustomDialog
    ...
    03-16 17:03:18.032: E/AndroidRuntime(20224): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.myview.CustomDialog" on path: .