首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ClassNotFoundException android.preference.ListView

ClassNotFoundException android.preference.ListView
EN

Stack Overflow用户
提问于 2016-05-26 00:06:48
回答 2查看 325关注 0票数 1

当我试图在我的安卓项目中使用PreferenceFragment时,我得到了下面的堆栈跟踪:

代码语言:javascript
复制
Process: com.fedorparetsky.parcare, PID: 25574
    android.view.InflateException: Binary XML file line #31: Error inflating class ListView
    ....
    Caused by: java.lang.ClassNotFoundException: Didn't find class "android.preference.ListView" on path: DexPathList[[zip file "/data/app/com.fedorparetsky.parcare-1/base.apk"],nativeLibraryDirectories=[/data/app/com.fedorparetsky.parcare-1/lib/arm, /vendor/lib, /system/lib]]

下面是PreferencesFragment的XML,称为preferences.xml:

代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">

    <PreferenceCategory
        android:title="General">
    </PreferenceCategory>

    <PreferenceCategory
        android:title="Account">

        <Preference android:title="Change Email"
            android:key="@string/changeEmailButton"
            android:summary="Change Email Summary"/>
        <Preference android:title="Change Password"
            android:key="@string/changePasswordButton"
            android:summary="Change Password Summary"/>

    </PreferenceCategory>

    <PreferenceCategory
        android:title="About">
        <Preference
            android:title="Our Website">
            <intent android:action="android.intent.action.VIEW"
                android:data="http://parcare.me" />
        </Preference>

    </PreferenceCategory>

    <ListView
        android:id="@android:id/list"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="5dp" />

</PreferenceScreen>

下面是SettingsFragment.java,片段的代码:

代码语言:javascript
复制
import android.os.Bundle;
import android.preference.PreferenceFragment;

import com.fedorparetsky.parcare.R;


public class SettingsFragment extends PreferenceFragment {


@Override
public void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.preferences);


}

这是我在输入片段时所称的:

代码语言:javascript
复制
fm.beginTransaction().replace(R.id.content_frame, new SettingsFragment()).commit();

为了能够克服这个错误,我需要修改什么?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2016-05-26 00:18:41

ListView不是可以作为首选项布局一部分的合法控件。

可以在首选项布局中使用以下控件:

  • CheckBoxPreference
  • ListPreference
  • EditTextPreference
票数 1
EN

Stack Overflow用户

发布于 2016-05-26 00:14:46

您不能在这样的XML中组合ViewPreference。选一个或另一个。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37449527

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档