I want to implement a preference screen. So I followed basically the example from the developer docs. When I start the Activity I see the header list, with one header (this part seems to work). But as soon I click this header the Activity crashed with below log.
我搜索了SO和gogle,但找不到关于这一错误的任何进一步信息。
我试图将pvis_appearance_ Screen.xml缩短到一个“BoxP参比项目”。 XML第18条也存在同样的错误。 因此,我猜测,这一错误不在档案中。
My activity class:
public class TrainerPreferenceActivity extends PreferenceActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public void onBuildHeaders(List<Header> target) {
loadHeadersFromResource(R.xml.preference_headers, target);
}
public static class AppearancePrefFragment extends PreferenceFragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preference_appearance_screen);
}
}
}
pvis_headers.xml file:
<?xml version="1.0" encoding="utf-8"?>
<preference-headers
xmlns:android="http://schemas.android.com/apk/res/android">
<header android:fragment=".TrainerPreferenceActivity$AppearancePrefFragment"
android:title="Appearance"
android:summary="An example of some preferences." />
</preference-headers>
pvis_appearance_ Screen.xml file:
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory
android:title="@string/pref_app_cat_theme">
</PreferenceCategory>
<PreferenceCategory
android:title="@string/pref_app_cat_background">
<CheckBoxPreference
android:key="@string/pref_app_bg_iscustom_key"
android:title="@string/pref_app_bg_iscustom_title"
android:summary="An example of some preferences."/>
<CheckBoxPreference
android:key="@string/pref_app_bg_hascolor_key"
android:title="@string/pref_app_bg_hascolor_title"
android:summary="An example of some preferences."/>
<CheckBoxPreference
android:key="@string/pref_app_bg_hasimage_key"
android:title="@string/pref_app_bg_hasimage_title"
android:summary="An example of some preferences."/>
</PreferenceCategory>
<PreferenceCategory
android:title="@string/pref_app_cat_behavior">
<CheckBoxPreference
android:key="@string/pref_app_orientationisenabled_key"
android:title="@string/pref_app_orientationisenabled_title"
android:summary="An example of some preferences."/>
<CheckBoxPreference
android:key="@string/pref_app_gestureisenabled_key"
android:title="@string/pref_app_gestureisenabled_title"
android:summary="An example of some preferences."/>
</PreferenceCategory>
</PreferenceScreen>
LogCat:
04-30 17:22:01.215: E/AndroidRuntime(16775): FATAL EXCEPTION: main 04-30 17:22:01.215: E/AndroidRuntime(16775): java.lang.RuntimeException: Binary XML file line #18: You must supply a layout_width attribute. 04-30 17:22:01.215: E/AndroidRuntime(16775): at android.content.res.TypedArray.getLayoutDimension(TypedArray.java:491) 04-30 17:22:01.215: E/AndroidRuntime(16775): at android.view.ViewGroup$LayoutParams.setBaseAttributes(ViewGroup.java:5318) 04-30 17:22:01.215: E/AndroidRuntime(16775): at android.view.ViewGroup$LayoutParams.(ViewGroup.java:5271) 04-30 17:22:01.215: E/AndroidRuntime(16775): at android.widget.AbsListView$LayoutParams.(AbsListView.java:5718) 04-30 17:22:01.215: E/AndroidRuntime(16775): at android.widget.AbsListView.generateLayoutParams(AbsListView.java:5355) 04-30 17:22:01.215: E/AndroidRuntime(16775): at android.widget.AbsListView.generateLayoutParams(AbsListView.java:86) 04-30 17:22:01.215: E/AndroidRuntime(16775): at android.view.LayoutInflater.inflate(LayoutInflater.java:477) 04-30 17:22:01.215: E/AndroidRuntime(16775): at android.view.LayoutInflater.inflate(LayoutInflater.java:396) 04-30 17:22:01.215: E/AndroidRuntime(16775): at android.preference.Preference.onCreateView(Preference.java:474) 04-30 17:22:01.215: E/AndroidRuntime(16775): at android.preference.Preference.getView(Preference.java:451) 04-30 17:22:01.215: E/AndroidRuntime(16775): at android.preference.PreferenceGroupAdapter.getView(PreferenceGroupAdapter.java:221) 04-30 17:22:01.215: E/AndroidRuntime(16775): at android.widget.AbsListView.obtainView(AbsListView.java:2033) 04-30 17:22:01.215: E/AndroidRuntime(16775): at android.widget.ListView.onMeasure(ListView.java:1127) 04-30 17:22:01.215: E/AndroidRuntime(16775): at android.view.View.measure(View.java:12723) 04-30 17:22:01.215: E/AndroidRuntime(16775): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4698) 04-30 17:22:01.215: E/AndroidRuntime(16775): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1369) 04-30 17:22:01.215: E/AndroidRuntime(16775): at android.widget.LinearLayout.measureVertical(LinearLayout.java:660) 04-30 17:22:01.215: E/AndroidRuntime(16775): at android.widget.LinearLayout.onMeasure(LinearLayout.java:553) 04-30 17:22:01.215: E/AndroidRuntime(16775): at android.view.View.measure(View.java:12723) 04-30 17:22:01.215: E/AndroidRuntime(16775): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4698) 04-30 17:22:01.215: E/AndroidRuntime(16775): at android.widget.FrameLayout.onMeasure(FrameLayout.java:293) 04-30 17:22:01.215: E/AndroidRuntime(16775): at android.view.View.measure(View.java:12723) 04-30 17:22:01.215: E/AndroidRuntime(16775): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4698) 04-30 17:22:01.215: E/AndroidRuntime(16775): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1369) 04-30 17:22:01.215: E/AndroidRuntime(16775): at android.widget.LinearLayout.measureVertical(LinearLayout.java:660) 04-30 17:22:01.215: E/AndroidRuntime(16775): at android.widget.LinearLayout.onMeasure(LinearLayout.java:553) 04-30 17:22:01.215: E/AndroidRuntime(16775): at android.view.View.measure(View.java:12723) 04-30 17:22:01.215: E/AndroidRuntime(16775): at android.widget.LinearLayout.measureHorizontal(LinearLayout.java:999) 04-30 17:22:01.215: E/AndroidRuntime(16775): at android.widget.LinearLayout.onMeasure(LinearLayout.java:555) 04-30 17:22:01.215: E/AndroidRuntime(16775): at android.view.View.measure(View.java:12723) 04-30 17:22:01.215: E/AndroidRuntime(16775): at android.widget.LinearLayout.measureVertical(LinearLayout.java:812) 04-30 17:22:01.215: E/AndroidRuntime(16775): at android.widget.LinearLayout.onMeasure(LinearLayout.java:553) 04-30 17:22:01.215: E/AndroidRuntime(16775): at android.view.View.measure(View.java:12723) 04-30 17:22:01.215: E/AndroidRuntime(16775): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4698) 04-30 17:22:01.215: E/AndroidRuntime(16775): at android.widget.FrameLayout.onMeasure(FrameLayout.java:293) 04-30 17:22:01.215: E/AndroidRuntime(16775): at android.view.View.measure(View.java:12723) 04-30 17:22:01.215: E/AndroidRuntime(16775): at android.widget.LinearLayout.measureVertical(LinearLayout.java:812) 04-30 17:22:01.215: E/AndroidRuntime(16775): at android.widget.LinearLayout.onMeasure(LinearLayout.java:553) 04-30 17:22:01.215: E/AndroidRuntime(16775): at android.view.View.measure(View.java:12723) 04-30 17:22:01.215: E/AndroidRuntime(16775): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4698) 04-30 17:22:01.215: E/AndroidRuntime(16775): at android.widget.FrameLayout.onMeasure(FrameLayout.java:293) 04-30 17:22:01.215: E/AndroidRuntime(16775): at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2092) 04-30 17:22:01.215: E/AndroidRuntime(16775): at android.view.View.measure(View.java:12723) 04-30 17:22:01.215: E/AndroidRuntime(16775): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1064) 04-30 17:22:01.215: E/AndroidRuntime(16775): at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2442) 04-30 17:22:01.215: E/AndroidRuntime(16775): at android.os.Handler.dispatchMessage(Handler.java:99) 04-30 17:22:01.215: E/AndroidRuntime(16775): at android.os.Looper.loop(Looper.java:137) 04-30 17:22:01.215: E/AndroidRuntime(16775): at android.app.ActivityThread.main(ActivityThread.java:4424) 04-30 17:22:01.215: E/AndroidRuntime(16775): at java.lang.reflect.Method.invokeNative(Native Method) 04-30 17:22:01.215: E/AndroidRuntime(16775): at java.lang.reflect.Method.invoke(Method.java:511) 04-30 17:22:01.215: E/AndroidRuntime(16775): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784) 04-30 17:22:01.215: E/AndroidRuntime(16775): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551) 04-30 17:22:01.215: E/AndroidRuntime(16775): at dalvik.system.NativeStart.main(Native Method)