偏好中的折旧方法导致错误无法计算

时间:2015-01-25 09:05:04

标签: java android eclipse logcat preferences

你好人们很难在新的时候弄清楚错误,即使你在前一个问题上得到负面的声誉,所以在经过2天的艰苦研究后我仍然没有弄清楚问题。

我正在从eclipse中的newboston系列中学习并且某些方法已被折旧但我搜索它在程序中无关紧要,现在以后可能会删除。

这是代码:

这是我的prefs课程。

 public class Prefs extends PreferenceActivity{

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

//extra class for preference in 56 ;
        // stuck in depreciason method addpreffromresource.
}

我在mainfiest中添加了活动:

   <activity
        android:name="com.example.androidme.Prefs"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="com.example.androidme.Prefs" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>

这是我的菜单按钮,我点击偏好并开始我的活动。

案例R.id.preferences

    public boolean onOptionsItemSelected(MenuItem item) {
    // TODO Auto-generated method stub


    switch(item.getItemId())
    {
    case R.id.Aboutus:
            Intent i = new Intent(this,AboutUs.class);
            startActivity(i);
        break;

    case R.id.prefernces:
        Intent prefintent = new Intent(this,Prefs.class);
        startActivity(prefintent);

        break;

    case R.id.exit:
        finish();

        break;
        }
    return false;
}

我在logcat中得到了错误:

 01-25 08:55:33.684: E/AndroidRuntime(2074): FATAL EXCEPTION: main
 01-25 08:55:33.684: E/AndroidRuntime(2074): java.lang.RuntimeException:                         Unable to start activity     ComponentInfo{com.example.androidme/com.example.androidme.Prefs}:     android.view.InflateException: Binary XML file line #17: Error inflating class     java.lang.reflect.Constructor
01-25 08:55:33.684: E/AndroidRuntime(2074):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
01-25 08:55:33.684: E/AndroidRuntime(2074):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
01-25 08:55:33.684: E/AndroidRuntime(2074):     at android.app.ActivityThread.access$600(ActivityThread.java:141)
01-25 08:55:33.684: E/AndroidRuntime(2074):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
01-25 08:55:33.684: E/AndroidRuntime(2074):     at android.os.Handler.dispatchMessage(Handler.java:99)
01-25 08:55:33.684: E/AndroidRuntime(2074):     at android.os.Looper.loop(Looper.java:137)
01-25 08:55:33.684: E/AndroidRuntime(2074):     at android.app.ActivityThread.main(ActivityThread.java:5041)
01-25 08:55:33.684: E/AndroidRuntime(2074):     at java.lang.reflect.Method.invokeNative(Native Method)
01-25 08:55:33.684: E/AndroidRuntime(2074):     at java.lang.reflect.Method.invoke(Method.java:511)
01-25 08:55:33.684: E/AndroidRuntime(2074):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
01-25 08:55:33.684: E/AndroidRuntime(2074):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
01-25 08:55:33.684: E/AndroidRuntime(2074):     at dalvik.system.NativeStart.main(Native Method)
01-25 08:55:33.684: E/AndroidRuntime(2074): Caused by: android.view.InflateException: Binary XML file line #17: Error inflating class java.lang.reflect.Constructor
01-25 08:55:33.684: E/AndroidRuntime(2074):     at android.preference.GenericInflater.createItem(GenericInflater.java:397)
01-25 08:55:33.684: E/AndroidRuntime(2074):     at android.preference.GenericInflater.onCreateItem(GenericInflater.java:417)
01-25 08:55:33.684: E/AndroidRuntime(2074):     at android.preference.GenericInflater.createItemFromTag(GenericInflater.java:428)
01-25 08:55:33.684: E/AndroidRuntime(2074):     at android.preference.GenericInflater.rInflate(GenericInflater.java:481)
01-25 08:55:33.684: E/AndroidRuntime(2074):     at android.preference.GenericInflater.inflate(GenericInflater.java:326)
01-25 08:55:33.684: E/AndroidRuntime(2074):     at android.preference.GenericInflater.inflate(GenericInflater.java:263)
01-25 08:55:33.684: E/AndroidRuntime(2074):     at android.preference.PreferenceManager.inflateFromResource(PreferenceManager.java:269)
01-25 08:55:33.684: E/AndroidRuntime(2074):     at android.preference.PreferenceActivity.addPreferencesFromResource(PreferenceActivity.java:1424)
01-25 08:55:33.684: E/AndroidRuntime(2074):     at com.example.androidme.Prefs.onCreate(Prefs.java:13)
01-25 08:55:33.684: E/AndroidRuntime(2074):     at android.app.Activity.performCreate(Activity.java:5104)
01-25 08:55:33.684: E/AndroidRuntime(2074):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
01-25 08:55:33.684: E/AndroidRuntime(2074):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
01-25 08:55:33.684: E/AndroidRuntime(2074):     ... 11 more
01-25 08:55:33.684: E/AndroidRuntime(2074): Caused by: java.lang.reflect.InvocationTargetException
01-25 08:55:33.684: E/AndroidRuntime(2074):     at java.lang.reflect.Constructor.constructNative(Native Method)
01-25 08:55:33.684: E/AndroidRuntime(2074):     at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
01-25 08:55:33.684: E/AndroidRuntime(2074):     at android.preference.GenericInflater.createItem(GenericInflater.java:383)
01-25 08:55:33.684: E/AndroidRuntime(2074):     ... 22 more
01-25 08:55:33.684: E/AndroidRuntime(2074): Caused by: java.lang.NullPointerException
01-25 08:55:33.684: E/AndroidRuntime(2074):     at android.content.res.AssetManager.getResourceTextArray(AssetManager.java:214)
01-25 08:55:33.684: E/AndroidRuntime(2074):     at android.content.res.Resources.getTextArray(Resources.java:427)
01-25 08:55:33.684: E/AndroidRuntime(2074):     at android.content.res.TypedArray.getTextArray(TypedArray.java:628)
01-25 08:55:33.684: E/AndroidRuntime(2074):     at android.preference.ListPreference.<init>(ListPreference.java:51)
01-25 08:55:33.684: E/AndroidRuntime(2074):     ... 25 more

我也无法读取logcat,但我向我的朋友展示,他知道他告诉我错误是nullpointerexception并检查mainfest prefs和preferencesintent和xml。仍然没有发现问题。

这里是xml:

<?xml version="1.0" encoding="utf-8"?>

<EditTextPreference 
   android:title="EditText"
   android:key="name"
   android:summary="Enter Your name"
    />

<CheckBoxPreference
    android:title="Checkbox"
    android:key="chckbox"
    android:summary="Select this box"
    android:defaultValue="true"
   ></CheckBoxPreference>

<ListPreference
    android:title="ListView"
    android:key="listview"
    android:summary="choose one from list"
    android:entries="@+array/list"
    android:entryValues="@+array/lValue"
    ></ListPreference>

这是xml值。 array.xml     enter code here

<EditTextPreference 
   android:title="EditText"
   android:key="name"
   android:summary="Enter Your name"
    />

<CheckBoxPreference
    android:title="Checkbox"
    android:key="chckbox"
    android:summary="Select this box"
    android:defaultValue="true"
   ></CheckBoxPreference>

<ListPreference
    android:title="ListView"
    android:key="listview"
    android:summary="choose one from list"
    android:entries="@+array/list"
    android:entryValues="@+array/lValue"
    ></ListPreference>

如果需要其他任何东西我在这里并提前感谢你。

0 个答案:

没有答案