07-25 10:41:02.048 7515-7515/com.example.sunshine E/AndroIDRuntime﹕ FATAL EXCEPTION: main java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.sunshine/com.example.sunshine.SettingsActivity}: java.lang.RuntimeException: Content has vIEw with ID attribute 'androID.R.ID.List' that is not a ListVIEw class at androID.app.ActivityThread.performlaunchActivity(ActivityThread.java:2063) at androID.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2088) at androID.app.ActivityThread.access0(ActivityThread.java:134) at androID.app.ActivityThread$H.handleMessage(ActivityThread.java:1199) at androID.os.Handler.dispatchMessage(Handler.java:99) at androID.os.Looper.loop(Looper.java:137) at androID.app.ActivityThread.main(ActivityThread.java:4744) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:511) at com.androID.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786) at com.androID.internal.os.ZygoteInit.main(ZygoteInit.java:553) at dalvik.system.NativeStart.main(Native Method) Caused by: java.lang.RuntimeException: Content has vIEw with ID attribute 'androID.R.ID.List' that is not a ListVIEw class at androID.preference.PreferenceFragment.ensureList(PreferenceFragment.java:350) at androID.preference.PreferenceFragment.getListVIEw(PreferenceFragment.java:336) at androID.preference.PreferenceFragment.bindPreferences(PreferenceFragment.java:330) at androID.preference.PreferenceFragment.onActivityCreated(PreferenceFragment.java:171) at androID.app.FragmentManagerImpl.movetoState(FragmentManager.java:852) at androID.app.FragmentManagerImpl.movetoState(FragmentManager.java:1039) at androID.app.BackStackRecord.run(BackStackRecord.java:635) at androID.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1411) at androID.app.Activity.performStart(Activity.java:5017) at androID.app.ActivityThread.performlaunchActivity(ActivityThread.java:2036) at androID.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2088) at androID.app.ActivityThread.access0(ActivityThread.java:134) at androID.app.ActivityThread$H.handleMessage(ActivityThread.java:1199) at androID.os.Handler.dispatchMessage(Handler.java:99) at androID.os.Looper.loop(Looper.java:137) at androID.app.ActivityThread.main(ActivityThread.java:4744) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:511) at com.androID.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786) at com.androID.internal.os.ZygoteInit.main(ZygoteInit.java:553) at dalvik.system.NativeStart.main(Native Method)
当我搜索SO时,我发现崩溃与ListFragment有些相关.但我确信我没有在我的应用程序中使用它. PreferenceFragment可能已经调用了它.我无法在这里查明问题.你能帮我解决一下吗?
这是我正在使用的首选xml –
<?xml version="1.0" enCoding="utf-8"?><PreferenceScreen xmlns:androID="http://schemas.androID.com/apk/res/androID" androID:layout_wIDth="match_parent" androID:layout_height="match_parent" > <EditTextPreference androID:title="@string/pref_location_label" androID:key="@string/pref_location_key" androID:defaultValue="@string/pref_location_default" androID:inputType="text" androID:singleline="true" /></PreferenceScreen>
这里是SettingsActivity,还有Fragment –
public class SettingsActivity extends Activity { @OverrIDe protected voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentVIEw(R.layout.activity_settings); if (savedInstanceState == null) { getFragmentManager().beginTransaction() .add(R.ID.container,new SettingsFragment()) .commit(); } } public static class SettingsFragment extends PreferenceFragment implements Preference.OnPreferencechangelistener { public SettingsFragment() { } @OverrIDe public voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Add 'general' preferences,defined in the XML file addPreferencesFromresource(R.xml.pref_general); // For all preferences,attach an OnPreferencechangelistener so the UI summary can be // updated when the preference changes. bindPreferenceSummaryTovalue(findPreference(getString(R.string.pref_location_key))); } @OverrIDe public VIEw onCreateVIEw(LayoutInflater inflater,VIEwGroup container,Bundle savedInstanceState) { VIEw rootVIEw = inflater.inflate(R.layout.fragment_settings,container,false); return rootVIEw; } /** * Attaches a Listener so the summary is always updated with the preference value. * Also fires the Listener once,to initialize the summary (so it shows up before the value * is changed.) */ private voID bindPreferenceSummaryTovalue(Preference preference) { // Set the Listener to watch for value changes. preference.setonPreferencechangelistener(this); // Trigger the Listener immediately with the preference's // current value. onPreferenceChange(preference,PreferenceManager .getDefaultSharedPreferences(preference.getContext()) .getString(preference.getKey(),"")); } @OverrIDe public boolean onPreferenceChange(Preference preference,Object value) { String stringValue = value.toString(); if (preference instanceof ListPreference) { // For List preferences,look up the correct display value in // the preference's 'entrIEs' List (since they have separate labels/values). ListPreference ListPreference = (ListPreference) preference; int prefIndex = ListPreference.findindexOfValue(stringValue); if (prefIndex >= 0) { preference.setSummary(ListPreference.getEntrIEs()[prefIndex]); } } else { // For other preferences,set the summary to the value's simple string representation. preference.setSummary(stringValue); } return true; } }}
还有什么我需要改变才能使它适用于Fragments而不是Activity吗?
解决方法 终于找到了.我只需要在我的片段的xml中放入一个带有androID:ID =“@ ID / androID:List”属性的ListVIEw.虽然我不知道为什么我需要它,但只是通过反复试验找到它. 总结以上是内存溢出为你收集整理的android – PreferenceFragment中的RunTimeException全部内容,希望文章能够帮你解决android – PreferenceFragment中的RunTimeException所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)