1

I have some problems with my XML code i hope you can help me with.

I have this class in this package:

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
    }
}

And then i have this preference xml file:

<?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>

And when i run the code i get this error:

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: .

To summarize my problem, i wanna know how to change the path the xml file is looking at, or figure out why it can't inflate my custom view.

Thanks in advance :)

1 Answers1

0

I ran into essentially the same issue you mention above. I assume you tried to switch back and forth between the Graphical Layout and the xml views for your preference xml file, right? Here's my cheap way of getting past my initialization issue (which should be similar to your ClassNotFoundException issue):

  1. Copy an existing class which is referenced similarly in the xml (aka has something like com...ClassName ... in the xml, and rename the 'ClassName' to CustomDialog (in your particular case)
  2. After doing this, I still got a 'class not found' error - I just rebuild my entire project and this error was gone. My newly created widget rendered accordingly in the graphical layout.

I have yet to see if I run into the inflating errors you did, but I hope my answer still helps somewhat. Sorry if it didn't, this is actually my first post on stackoverflow, and I am admittedly a n00b when it comes to Android. Learning as I go along too :)

Mhd. Yasseen
  • 1,027
  • 3
  • 16
  • 27