Android 2.3.3
Eclipse Version: 3.7.0
LogCat
LogCat 报错信息:
02-08 10:29:00.171: WARN/dalvikvm(825): threadid=1: thread exiting with uncaught exception (group=0x40025560)
02-08 10:29:00.221: ERROR/AndroidRuntime(825): FATAL EXCEPTION: main
02-08 10:29:00.221: ERROR/AndroidRuntime(825): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.taobao.nokia/com.taobao.nokia.manage.Preference}:
android.content.res.Resources$NotFoundException: String resource ID #0x7f070088
02-08 10:29:00.221: ERROR/AndroidRuntime(825): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
02-08 10:29:00.221: ERROR/AndroidRuntime(825): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
02-08 10:29:00.221: ERROR/AndroidRuntime(825): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
02-08 10:29:00.221: ERROR/AndroidRuntime(825): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
02-08 10:29:00.221: ERROR/AndroidRuntime(825): at android.os.Handler.dispatchMessage(Handler.java:99)
02-08 10:29:00.221: ERROR/AndroidRuntime(825): at android.os.Looper.loop(Looper.java:123)
02-08 10:29:00.221: ERROR/AndroidRuntime(825): at android.app.ActivityThread.main(ActivityThread.java:3683)
02-08 10:29:00.221: ERROR/AndroidRuntime(825): at java.lang.reflect.Method.invokeNative(Native Method)
02-08 10:29:00.221: ERROR/AndroidRuntime(825): at java.lang.reflect.Method.invoke(Method.java:507)
02-08 10:29:00.221: ERROR/AndroidRuntime(825): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
02-08 10:29:00.221: ERROR/AndroidRuntime(825): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
02-08 10:29:00.221: ERROR/AndroidRuntime(825): at dalvik.system.NativeStart.main(Native Method)
02-08 10:29:00.221: ERROR/AndroidRuntime(825): Caused by: android.content.res.Resources$NotFoundException: String resource ID #0x7f070088
02-08 10:29:00.221: ERROR/AndroidRuntime(825): at android.content.res.Resources.getText(Resources.java:201)
02-08 10:29:00.221: ERROR/AndroidRuntime(825): at android.content.res.Resources.getString(Resources.java:254)
02-08 10:29:00.221: ERROR/AndroidRuntime(825): at android.content.Context.getString(Context.java:183)
02-08 10:29:00.221: ERROR/AndroidRuntime(825): at com.taobao.nokia.manage.Preference.getDeviceid(Preference.java:384)
02-08 10:29:00.221: ERROR/AndroidRuntime(825): at com.taobao.nokia.manage.Preference.setSummary(Preference.java:150)
02-08 10:29:00.221: ERROR/AndroidRuntime(825): at com.taobao.nokia.manage.Preference.onCreate(Preference.java:88)
02-08 10:29:00.221: ERROR/AndroidRuntime(825): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
02-08 10:29:00.221: ERROR/AndroidRuntime(825): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
02-08 10:29:00.221: ERROR/AndroidRuntime(825): ... 11 more
主要错误:
02-08 10:29:00.221: ERROR/AndroidRuntime(825): Caused by: android.content.res.Resources$NotFoundException: String resource ID #0x7f070088
发生错误原因分析:
Activity部分源代码:
public String getDeviceid() {
String setting = sharedPref.getString(Preference.KEY_deviceid,
context.getString(R.string.def_deviceid));
return setting;
}
Eclispe并未提示R.string.def_deviceid存在“def_deviceid cannot be resolved or is not a field”问题;
经查找,发现:因为支持国际化,在res下设置了中文和英文两套资源文件,中文资源为默认资源。
英文资源中已有
<string name="def_deviceid">nokia</string>
而中文资源中没有相应配置。
Android虚拟机设置为默认中文,因此运行应用时找不到相应资源而报错。
解决办法:在中文资源中添加相应配置。