preferenceScreen类未找到 [英] PreferenceScreen class not found

查看:180
本文介绍了preferenceScreen类未找到的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的preferences.xml

I have this in preferences.xml

<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">

    <CheckBoxPreference
        android:key="displayNotification"
        android:title="Display notification"
        />

    <ListPreference
        android:entries="@array/languages"
        android:key="language"
        />
</PreferenceScreen>

preferencesActivity.java,使用此XML类

PreferencesActivity.java, the class that uses this xml

public class PreferencesActivity extends PreferenceActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);

        setContentView(R.xml.preferences);
    }
}

和我有它在清单像这样

<activity android:name="com.tellthetime.PreferencesActivity" />

当我开始活动,我收到了找不到类的异常,我不明白。

When I start the activity I get a class not found exception, which I don't understand.

05-17 00:35:13.633: ERROR/AndroidRuntime(212): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.tellthetime/com.tellthetime.PreferencesActivity}: android.view.InflateException: Binary XML file line #2: Error inflating class PreferenceScreen
05-17 00:35:13.633: ERROR/AndroidRuntime(212):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2496)
05-17 00:35:13.633: ERROR/AndroidRuntime(212):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
05-17 00:35:13.633: ERROR/AndroidRuntime(212):     at android.app.ActivityThread.access$2200(ActivityThread.java:119)
05-17 00:35:13.633: ERROR/AndroidRuntime(212):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
05-17 00:35:13.633: ERROR/AndroidRuntime(212):     at android.os.Handler.dispatchMessage(Handler.java:99)
05-17 00:35:13.633: ERROR/AndroidRuntime(212):     at android.os.Looper.loop(Looper.java:123)
05-17 00:35:13.633: ERROR/AndroidRuntime(212):     at android.app.ActivityThread.main(ActivityThread.java:4363)
05-17 00:35:13.633: ERROR/AndroidRuntime(212):     at java.lang.reflect.Method.invokeNative(Native Method)
05-17 00:35:13.633: ERROR/AndroidRuntime(212):     at java.lang.reflect.Method.invoke(Method.java:521)
05-17 00:35:13.633: ERROR/AndroidRuntime(212):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
05-17 00:35:13.633: ERROR/AndroidRuntime(212):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
05-17 00:35:13.633: ERROR/AndroidRuntime(212):     at dalvik.system.NativeStart.main(Native Method)
05-17 00:35:13.633: ERROR/AndroidRuntime(212): Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class PreferenceScreen
05-17 00:35:13.633: ERROR/AndroidRuntime(212):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:576)
05-17 00:35:13.633: ERROR/AndroidRuntime(212):     at android.view.LayoutInflater.inflate(LayoutInflater.java:385)
05-17 00:35:13.633: ERROR/AndroidRuntime(212):     at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
05-17 00:35:13.633: ERROR/AndroidRuntime(212):     at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
05-17 00:35:13.633: ERROR/AndroidRuntime(212):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:198)
05-17 00:35:13.633: ERROR/AndroidRuntime(212):     at android.app.Activity.setContentView(Activity.java:1622)
05-17 00:35:13.633: ERROR/AndroidRuntime(212):     at com.tellthetime.PreferencesActivity.onCreate(PreferencesActivity.java:13)
05-17 00:35:13.633: ERROR/AndroidRuntime(212):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
05-17 00:35:13.633: ERROR/AndroidRuntime(212):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
05-17 00:35:13.633: ERROR/AndroidRuntime(212):     ... 11 more
05-17 00:35:13.633: ERROR/AndroidRuntime(212): Caused by: java.lang.ClassNotFoundException: android.view.PreferenceScreen in loader dalvik.system.PathClassLoader@44c067e8
05-17 00:35:13.633: ERROR/AndroidRuntime(212):     at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
05-17 00:35:13.633: ERROR/AndroidRuntime(212):     at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
05-17 00:35:13.633: ERROR/AndroidRuntime(212):     at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
05-17 00:35:13.633: ERROR/AndroidRuntime(212):     at android.view.LayoutInflater.createView(LayoutInflater.java:466)
05-17 00:35:13.633: ERROR/AndroidRuntime(212):     at android.view.LayoutInflater.onCreateView(LayoutInflater.java:544)
05-17 00:35:13.633: ERROR/AndroidRuntime(212):     at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:66)
05-17 00:35:13.633: ERROR/AndroidRuntime(212):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)
05-17 00:35:13.633: ERROR/AndroidRuntime(212):     ... 19 more

这已经问<一href="http://stackoverflow.com/questions/5765412/android-app-crashes-immediately-when-$p$pferences-screen-is-started">here但没有人回答。正如在该线程由海科鲁普,Android是寻找类在包 android.view ,但类是在机器人。preferences ,这真的失去了我。

This was already asked here but no one answered. As pointed out in that thread by Heiko Rupp, android is looking for the class in the package android.view, but the class is in android.preferences, this really lost me.

推荐答案

你感到困惑,你要设置的 preference 的定义中的布局定义。首先设置一个布局的活动,然后绑定你的preferences XML:

You're getting confused, you're trying to set the preference definition as the layout definition. First set a layout for the Activity, then bind your preferences XML:

  ...
  setContentView(R.layout.layout);
  addPreferencesFromResource(R.xml.preferences);
  ...

这篇关于preferenceScreen类未找到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆