English 中文(简体)
优惠价格暴涨/优惠行为失灵——说明原因。
原标题:PreferenceFragment / PreferenceActivity crashes - cant figure out why

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)

最佳回答

右手,我设立了一个快速测试项目,但我没有能够复制这一错误——在我的银河上显示并做罚款。 你们掌握了什么手段,你们是否尝试过任何其他/策划者?

The only possibly related issue I could find is this style/theming-related one, which seems to pop up every here and there. Have you made any customizations? If so, try running above code as vanilla as possible to see if that makes a difference.

问题回答

这是因为你提到了你使用的习惯风格,正由优惠屏幕使用,而习俗风格并不继承这些要求的财产。 为了保护你的习惯风格并避免这一问题,确保你的习俗风格具有“传教”和“传教”性质。 阁下:

    <style name="MyListSeperator" parent="android:Widget.Holo.Light.TextView">
        <item name="android:layout_width">match_parent</item>
        <item name="android:layout_height">wrap_content</item>
        ...
    </style>

接着,你走了一步:

    <item name="android:listSeparatorTextViewStyle">@style/MyListSeparator</item>




相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签