1
我使用holoeverywhere庫,當我開始ActivityPreference我收到此錯誤:SeekBarPreference/NumberPickerPreference ClassCastException異常
06-22 22:54:23.425: E/AndroidRuntime(11853): FATAL EXCEPTION: main
06-22 22:54:23.425: E/AndroidRuntime(11853): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.tufan.liveprices/com.tufan.liveprices.ActivityPreferences}: java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer
06-22 22:54:23.425: E/AndroidRuntime(11853): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2100)
06-22 22:54:23.425: E/AndroidRuntime(11853): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2125)
06-22 22:54:23.425: E/AndroidRuntime(11853): at android.app.ActivityThread.access$600(ActivityThread.java:140)
06-22 22:54:23.425: E/AndroidRuntime(11853): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1227)
06-22 22:54:23.425: E/AndroidRuntime(11853): at android.os.Handler.dispatchMessage(Handler.java:99)
06-22 22:54:23.425: E/AndroidRuntime(11853): at android.os.Looper.loop(Looper.java:137)
06-22 22:54:23.425: E/AndroidRuntime(11853): at android.app.ActivityThread.main(ActivityThread.java:4898)
06-22 22:54:23.425: E/AndroidRuntime(11853): at java.lang.reflect.Method.invokeNative(Native Method)
06-22 22:54:23.425: E/AndroidRuntime(11853): at java.lang.reflect.Method.invoke(Method.java:511)
06-22 22:54:23.425: E/AndroidRuntime(11853): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
06-22 22:54:23.425: E/AndroidRuntime(11853): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
06-22 22:54:23.425: E/AndroidRuntime(11853): at dalvik.system.NativeStart.main(Native Method)
06-22 22:54:23.425: E/AndroidRuntime(11853): Caused by: java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer
06-22 22:54:23.425: E/AndroidRuntime(11853): at android.app.SharedPreferencesImpl.getInt(SharedPreferencesImpl.java:221)
06-22 22:54:23.425: E/AndroidRuntime(11853): at org.holoeverywhere.preference._SharedPreferencesImpl_XML.getInt(_SharedPreferencesImpl_XML.java:232)
06-22 22:54:23.425: E/AndroidRuntime(11853): at org.holoeverywhere.preference._SharedPreferencesImpl_XML.getInt(_SharedPreferencesImpl_XML.java:232)
06-22 22:54:23.425: E/AndroidRuntime(11853): at org.holoeverywhere.preference.Preference.getPersistedInt(Preference.java:332)
06-22 22:54:23.425: E/AndroidRuntime(11853): at org.holoeverywhere.preference.NumberPickerPreference.onSetInitialValue(NumberPickerPreference.java:190)
06-22 22:54:23.425: E/AndroidRuntime(11853): at org.holoeverywhere.preference.Preference.dispatchSetInitialValue(Preference.java:202)
06-22 22:54:23.425: E/AndroidRuntime(11853): at org.holoeverywhere.preference.Preference.onAttachedToHierarchy(Preference.java:492)
06-22 22:54:23.425: E/AndroidRuntime(11853): at org.holoeverywhere.preference.PreferenceGroup.addPreference(PreferenceGroup.java:74)
06-22 22:54:23.425: E/AndroidRuntime(11853): at org.holoeverywhere.preference.PreferenceGroup.addItemFromInflater(PreferenceGroup.java:40)
06-22 22:54:23.425: E/AndroidRuntime(11853): at org.holoeverywhere.preference.PreferenceGroup.addItemFromInflater(PreferenceGroup.java:1)
06-22 22:54:23.425: E/AndroidRuntime(11853): at org.holoeverywhere.internal.GenericInflater.rInflate(GenericInflater.java:262)
06-22 22:54:23.425: E/AndroidRuntime(11853): at org.holoeverywhere.internal.GenericInflater.rInflate(GenericInflater.java:263)
06-22 22:54:23.425: E/AndroidRuntime(11853): at org.holoeverywhere.internal.GenericInflater.inflate(GenericInflater.java:194)
06-22 22:54:23.425: E/AndroidRuntime(11853): at org.holoeverywhere.internal.GenericInflater.inflate(GenericInflater.java:164)
06-22 22:54:23.425: E/AndroidRuntime(11853): at org.holoeverywhere.internal.GenericInflater.inflate(GenericInflater.java:158)
06-22 22:54:23.425: E/AndroidRuntime(11853): at org.holoeverywhere.preference.PreferenceManager.inflateFromResource(PreferenceManager.java:380)
06-22 22:54:23.425: E/AndroidRuntime(11853): at org.holoeverywhere.preference.PreferenceActivity.addPreferencesFromResource(PreferenceActivity.java:282)
06-22 22:54:23.425: E/AndroidRuntime(11853): at com.tufan.liveprices.ActivityPreferences.onCreate(ActivityPreferences.java:15)
06-22 22:54:23.425: E/AndroidRuntime(11853): at android.app.Activity.performCreate(Activity.java:5206)
06-22 22:54:23.425: E/AndroidRuntime(11853): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1083)
06-22 22:54:23.425: E/AndroidRuntime(11853): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2064)
06-22 22:54:23.425: E/AndroidRuntime(11853): ... 11 more
PreferenceActivity:
package com.***;
import org.holoeverywhere.preference.PreferenceActivity;
import android.os.Bundle;
public class ActivityPreferences extends PreferenceActivity {
@SuppressWarnings("deprecation")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.activity_preferences);
}
}
activity_preferences.xml
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:holo="http://schemas.android.com/apk/res-auto">
<PreferenceCategory
holo:key="cat_refresh"
holo:title="@string/preferencecategory_refresh" >
<CheckBoxPreference
holo:key="autoRefresh"
holo:title="@string/preference_autorefreshtitle"
holo:summary="@string/preference_autorefreshsummary"
holo:defaultValue="true" />
<org.holoeverywhere.preference.NumberPickerPreference
holo:key="refreshInterval"
holo:title="@string/preference_refreshintervaltitle"
holo:summary="@string/preference_refreshintervalsummary"
holo:defaultValue="5"
holo:max="200"
holo:min="1" />
</PreferenceCategory>
</PreferenceScreen>
Holoeverywhere版本: 1.6.1
的Android SDK: 4.2
測試於:的Android 4.1.2(GT-I9300)
而且其中問題?我在哪裏犯錯?