1

The Sony D2203 runs Android 4.4.2 and the D2403 runs Android 4.4.4.

The specific line in the code that is giving the error is:

PreferenceManager.setDefaultValues(this,R.xml.preference,false);

This Is the logcat output of the error:

4-22 13:13:42.542  24913-24913/petra.com.wecapture E/AndroidRuntime? FATAL EXCEPTION: main
    Process: petra.com.wecapture, PID: 24913
    java.lang.RuntimeException: Unable to start activity ComponentInfo{petra.com.wecapture/petra.com.wecapture.MainActivity}: android.view.InflateException: Binary XML file line #6: Error inflating class petra.com.settings.MyEditTextPreference
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2246)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2296)
            at android.app.ActivityThread.access$800(ActivityThread.java:145)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1243)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5136)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:819)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:635)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: android.view.InflateException: Binary XML file line #6: Error inflating class petra.com.settings.MyEditTextPreference
            at android.preference.GenericInflater.createItem(GenericInflater.java:386)
            at android.preference.GenericInflater.createItemFromTag(GenericInflater.java:430)
            at android.preference.GenericInflater.rInflate(GenericInflater.java:481)
            at android.preference.GenericInflater.rInflate(GenericInflater.java:493)
            at android.preference.GenericInflater.inflate(GenericInflater.java:326)
            at android.preference.GenericInflater.inflate(GenericInflater.java:263)
            at android.preference.PreferenceManager.inflateFromResource(PreferenceManager.java:272)
            at android.preference.PreferenceManager.setDefaultValues(PreferenceManager.java:485)
            at android.preference.PreferenceManager.setDefaultValues(PreferenceManager.java:444)
            at petra.com.wecapture.MainActivity.onCreate(MainActivity.java:221)
            at android.app.Activity.performCreate(Activity.java:5231)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2210)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2296)
            at android.app.ActivityThread.access$800(ActivityThread.java:145)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1243)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5136)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:819)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:635)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: java.lang.NoSuchMethodException: <init> [class android.content.Context, interface android.util.AttributeSet]
            at java.lang.Class.getConstructorOrMethod(Class.java:472)
            at java.lang.Class.getConstructor(Class.java:446)
            at android.preference.GenericInflater.createItem(GenericInflater.java:377)
            at android.preference.GenericInflater.createItemFromTag(GenericInflater.java:430)
            at android.preference.GenericInflater.rInflate(GenericInflater.java:481)
            at android.preference.GenericInflater.rInflate(GenericInflater.java:493)
            at android.preference.GenericInflater.inflate(GenericInflater.java:326)
            at android.preference.GenericInflater.inflate(GenericInflater.java:263)
            at android.preference.PreferenceManager.inflateFromResource(PreferenceManager.java:272)
            at android.preference.PreferenceManager.setDefaultValues(PreferenceManager.java:485)
            at android.preference.PreferenceManager.setDefaultValues(PreferenceManager.java:444)
            at petra.com.wecapture.MainActivity.onCreate(MainActivity.java:221)
            at android.app.Activity.performCreate(Activity.java:5231)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2210)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2296)
            at android.app.ActivityThread.access$800(ActivityThread.java:145)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1243)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5136)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:819)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:635)
            at dalvik.system.NativeStart.main(Native Method)
device not found

Here is the MyEditTextPreference class:

    import android.content.Context;
    import android.preference.EditTextPreference;
    import android.util.AttributeSet;


    public class MyEditTextPreference extends EditTextPreference {
        public MyEditTextPreference(Context context, AttributeSet attrs, int defStyle) {
            super(context, attrs, defStyle);
        }

        @Override
        public void setText(String text) {
            super.setText(text);
            setSummary(text);
        }
    }

The preference XML file:

<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
    <PreferenceCategory
        android:title="App settings"
        android:key="pref_key_storage_settings">
    <petra.com.settings.MyEditTextPreference
        android:key="pref_serverpath"
        android:title="Server address"
        android:defaultValue="http://192.168.0.1/"
     />



        <petra.com.settings.MyEditTextPreference
            android:key="pref_servicename"
            android:title="Service Name"
            android:defaultValue="Service1.svc"
            />
        <CheckBoxPreference
            android:key="pref_firstrun"
            android:title="firstrun"
            android:defaultValue="true"
             />
</PreferenceCategory>
<PreferenceCategory
    android:title="Local Database Tools"
    android:key="pref_key_db_settings">
    <Preference
        android:key="pref_clean_db"
        android:title="Clean database"
        android:summary="All data in local database will be lost."
        android:enabled="true">
    </Preference>

</PreferenceCategory>


</PreferenceScreen>

Does anyone know why I would get this problem? I can't find anything to help on the web. It seems like there must be some compatibility issue with my code between Android 4.4.2 and Android 4.4.4 but I don't know what it is.

Nico Bos
  • 185
  • 1
  • 10

1 Answers1

0

Seems to me that different API versions use different default constructors of the Preference object when it is inflated from XML. You should always implement all default constructors whan subclassing inflated android objects. Your MyEditTextPreference should look like this

public class MyEditTextPreference extends EditTextPreference {

    public MyEditTextPreference(Context context) {
        super(context);
    }

    public MyEditTextPreference(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public MyEditTextPreference(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    @Override
    public void setText(String text) {
        super.setText(text);
        setSummary(text);
    }
}
Lamorak
  • 10,957
  • 9
  • 43
  • 57