FATAL EXCEPTION主要Android应用程序

时间:2011-11-14 17:26:19

标签: android eclipse exception preferences fatal-error

我目前正在开发Android应用。单击“菜单”时,菜单会显示,但如果选择“首选项”,则会崩溃。如果单击“新建”,它可以正常工作。我不知道发生了什么事。我是Android App开发和eclipse IDE的新手,所以一切都有帮助。这是LogCat:

11-14 12:14:44.665: E/AndroidRuntime(392): FATAL EXCEPTION: main
11-14 12:14:44.665: E/AndroidRuntime(392): java.util.UnknownFormatConversionException: Conversion: r
11-14 12:14:44.665: E/AndroidRuntime(392):  at java.util.Formatter$FormatToken.unknownFormatConversionException(Formatter.java:1420)
11-14 12:14:44.665: E/AndroidRuntime(392):  at java.util.Formatter$FormatToken.checkFlags(Formatter.java:1357)
11-14 12:14:44.665: E/AndroidRuntime(392):  at java.util.Formatter.transform(Formatter.java:1463)
11-14 12:14:44.665: E/AndroidRuntime(392):  at java.util.Formatter.doFormat(Formatter.java:1102)
11-14 12:14:44.665: E/AndroidRuntime(392):  at java.util.Formatter.format(Formatter.java:1063)
11-14 12:14:44.665: E/AndroidRuntime(392):  at java.util.Formatter.format(Formatter.java:1032)
11-14 12:14:44.665: E/AndroidRuntime(392):  at java.lang.String.format(String.java:2104)
11-14 12:14:44.665: E/AndroidRuntime(392):  at java.lang.String.format(String.java:2078)
11-14 12:14:44.665: E/AndroidRuntime(392):  at android.preference.ListPreference.getSummary(ListPreference.java:152)
11-14 12:14:44.665: E/AndroidRuntime(392):  at android.preference.Preference.onBindView(Preference.java:500)
11-14 12:14:44.665: E/AndroidRuntime(392):  at android.preference.Preference.getView(Preference.java:450)
11-14 12:14:44.665: E/AndroidRuntime(392):  at android.preference.PreferenceGroupAdapter.getView(PreferenceGroupAdapter.java:221)
11-14 12:14:44.665: E/AndroidRuntime(392):  at android.widget.AbsListView.obtainView(AbsListView.java:1949)
11-14 12:14:44.665: E/AndroidRuntime(392):  at android.widget.ListView.measureHeightOfChildren(ListView.java:1228)
11-14 12:14:44.665: E/AndroidRuntime(392):  at android.widget.ListView.onMeasure(ListView.java:1139)
11-14 12:14:44.665: E/AndroidRuntime(392):  at android.view.View.measure(View.java:10828)
11-14 12:14:44.665: E/AndroidRuntime(392):  at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4351)
11-14 12:14:44.665: E/AndroidRuntime(392):  at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1284)
11-14 12:14:44.665: E/AndroidRuntime(392):  at android.widget.LinearLayout.measureVertical(LinearLayout.java:613)
11-14 12:14:44.665: E/AndroidRuntime(392):  at android.widget.LinearLayout.onMeasure(LinearLayout.java:519)
11-14 12:14:44.665: E/AndroidRuntime(392):  at android.view.View.measure(View.java:10828)
11-14 12:14:44.665: E/AndroidRuntime(392):  at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4351)
11-14 12:14:44.665: E/AndroidRuntime(392):  at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1284)
11-14 12:14:44.665: E/AndroidRuntime(392):  at android.widget.LinearLayout.measureHorizontal(LinearLayout.java:956)
11-14 12:14:44.665: E/AndroidRuntime(392):  at android.widget.LinearLayout.onMeasure(LinearLayout.java:521)
11-14 12:14:44.665: E/AndroidRuntime(392):  at android.view.View.measure(View.java:10828)
11-14 12:14:44.665: E/AndroidRuntime(392):  at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4351)
11-14 12:14:44.665: E/AndroidRuntime(392):  at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1284)
11-14 12:14:44.665: E/AndroidRuntime(392):  at android.widget.LinearLayout.measureVertical(LinearLayout.java:613)
11-14 12:14:44.665: E/AndroidRuntime(392):  at android.widget.LinearLayout.onMeasure(LinearLayout.java:519)
11-14 12:14:44.665: E/AndroidRuntime(392):  at android.view.View.measure(View.java:10828)
11-14 12:14:44.665: E/AndroidRuntime(392):  at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4351)
11-14 12:14:44.665: E/AndroidRuntime(392):  at android.widget.FrameLayout.onMeasure(FrameLayout.java:267)
11-14 12:14:44.665: E/AndroidRuntime(392):  at android.view.View.measure(View.java:10828)
11-14 12:14:44.665: E/AndroidRuntime(392):  at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4351)
11-14 12:14:44.665: E/AndroidRuntime(392):  at android.widget.FrameLayout.onMeasure(FrameLayout.java:267)
11-14 12:14:44.665: E/AndroidRuntime(392):  at android.view.View.measure(View.java:10828)
11-14 12:14:44.665: E/AndroidRuntime(392):  at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4351)
11-14 12:14:44.665: E/AndroidRuntime(392):  at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1284)
11-14 12:14:44.665: E/AndroidRuntime(392):  at android.widget.LinearLayout.measureVertical(LinearLayout.java:613)
11-14 12:14:44.665: E/AndroidRuntime(392):  at android.widget.LinearLayout.onMeasure(LinearLayout.java:519)
11-14 12:14:44.665: E/AndroidRuntime(392):  at android.view.View.measure(View.java:10828)
11-14 12:14:44.665: E/AndroidRuntime(392):  at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4351)
11-14 12:14:44.665: E/AndroidRuntime(392):  at android.widget.FrameLayout.onMeasure(FrameLayout.java:267)
11-14 12:14:44.665: E/AndroidRuntime(392):  at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:1890)
11-14 12:14:44.665: E/AndroidRuntime(392):  at android.view.View.measure(View.java:10828)
11-14 12:14:44.665: E/AndroidRuntime(392):  at android.view.ViewRoot.performTraversals(ViewRoot.java:884)
11-14 12:14:44.665: E/AndroidRuntime(392):  at android.view.ViewRoot.handleMessage(ViewRoot.java:2003)
11-14 12:14:44.665: E/AndroidRuntime(392):  at android.os.Handler.dispatchMessage(Handler.java:99)
11-14 12:14:44.665: E/AndroidRuntime(392):  at android.os.Looper.loop(Looper.java:132)
11-14 12:14:44.665: E/AndroidRuntime(392):  at android.app.ActivityThread.main(ActivityThread.java:4025)
11-14 12:14:44.665: E/AndroidRuntime(392):  at java.lang.reflect.Method.invokeNative(Native Method)
11-14 12:14:44.665: E/AndroidRuntime(392):  at java.lang.reflect.Method.invoke(Method.java:491)
11-14 12:14:44.665: E/AndroidRuntime(392):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
11-14 12:14:44.665: E/AndroidRuntime(392):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
11-14 12:14:44.665: E/AndroidRuntime(392):  at dalvik.system.NativeStart.main(Native Method)

以下是崩溃时调用的方法:

/** when menu button option selected */
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.menu_options:
        startActivity(new Intent(this, WordSearchPreferences.class));
        return true;
    case R.id.menu_new:
        control.newWordSearch();
        return true;
    }return super.onOptionsItemSelected(item);
}

这是用于此的preferences.xml:

<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
    <ListPreference android:key="@string/prefs_size"
    android:title="@string/size" android:defaultValue="10"
    android:summary="@string/prefs_size_summary"
    android:entryValues="@array/sizes_list_values"
    android:entries="@array/sizes_list_labels" />
<ListPreference android:key="@string/prefs_category"
    android:title="@string/category" android:defaultValue="@string/RANDOM"
    android:summary="@string/prefs_category_summary"
    android:entryValues="@array/categories_list_values"
    android:entries="@array/categories_list_labels" />
<ListPreference android:key="@string/prefs_touch_mode"
    android:title="@string/input_type" android:defaultValue="@string/DRAG"
    android:summary="@string/prefs_touch_mode_summary"
    android:entryValues="@array/touch_mode_list_values"
    android:entries="@array/touch_mode_list_labels" />
<ListPreference android:key="@string/PREFS_THEME"
    android:title="@string/THEME" android:defaultValue="@string/THEME_ORIGINAL"
    android:summary="@string/PREFS_THEME_SUMMARY"
    android:entryValues="@array/THEME_VALUES"
    android:entries="@array/THEME_LABELS" />
</PreferenceScreen>

1 个答案:

答案 0 :(得分:5)

ListPreference使用String.format()生成首选项的摘要,因此您可以通过%s混合来自首选项本身的数据。您似乎在说明中使用了%或某些令人困惑的内容String.format()。请确保@string/prefs_size_summary和其他人的值与String.format()一致。

此外,通常您不会为android:key使用字符串资源,因为您不会翻译您的偏好键。仅对实际翻译的内容使用字符串资源。