当我试图在我的安卓项目中使用PreferenceFragment时,我得到了下面的堆栈跟踪:
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:
<?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,片段的代码:
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);
}这是我在输入片段时所称的:
fm.beginTransaction().replace(R.id.content_frame, new SettingsFragment()).commit();为了能够克服这个错误,我需要修改什么?
发布于 2016-05-26 00:18:41
发布于 2016-05-26 00:14:46
您不能在这样的XML中组合View和Preference。选一个或另一个。
https://stackoverflow.com/questions/37449527
复制相似问题