首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > 移动开发 >

国际化资源文件,配备不完整导致报错

2012-06-30 
国际化资源文件,配置不完整导致报错Android 2.3.3Eclipse Version: 3.7.0LogCat?LogCat 报错信息:02-07 23

国际化资源文件,配置不完整导致报错

Android 2.3.3Eclipse Version: 3.7.0LogCat

?LogCat 报错信息:

02-07 23:19:47.171: WARN/dalvikvm(825): threadid=1: thread exiting with uncaught exception (group=0x40015560)02-07 23:19:47.221: ERROR/AndroidRuntime(825): FATAL EXCEPTION: main02-07 23:19:47.221: ERROR/AndroidRuntime(825): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.tmall.htc/com.tmall.htc.manage.Config}: android.content.res.Resources$NotFoundException: String resource ID #0x7f07008802-07 23:19:47.221: ERROR/AndroidRuntime(825): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)02-07 23:19:47.221: ERROR/AndroidRuntime(825): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)02-07 23:19:47.221: ERROR/AndroidRuntime(825): at android.app.ActivityThread.access$1500(ActivityThread.java:117)02-07 23:19:47.221: ERROR/AndroidRuntime(825): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)02-07 23:19:47.221: ERROR/AndroidRuntime(825): at android.os.Handler.dispatchMessage(Handler.java:99)02-07 23:19:47.221: ERROR/AndroidRuntime(825): at android.os.Looper.loop(Looper.java:123)02-07 23:19:47.221: ERROR/AndroidRuntime(825): at android.app.ActivityThread.main(ActivityThread.java:3683)02-07 23:19:47.221: ERROR/AndroidRuntime(825): at java.lang.reflect.Method.invokeNative(Native Method)02-07 23:19:47.221: ERROR/AndroidRuntime(825): at java.lang.reflect.Method.invoke(Method.java:507)02-07 23:19:47.221: ERROR/AndroidRuntime(825): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)02-07 23:19:47.221: ERROR/AndroidRuntime(825): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)02-07 23:19:47.221: ERROR/AndroidRuntime(825): at dalvik.system.NativeStart.main(Native Method)02-07 23:19:47.221: ERROR/AndroidRuntime(825): Caused by: android.content.res.Resources$NotFoundException: String resource ID #0x7f07008802-07 23:19:47.221: ERROR/AndroidRuntime(825): at android.content.res.Resources.getText(Resources.java:201)02-07 23:19:47.221: ERROR/AndroidRuntime(825): at android.content.res.Resources.getString(Resources.java:254)02-07 23:19:47.221: ERROR/AndroidRuntime(825): at android.content.Context.getString(Context.java:183)02-07 23:19:47.221: ERROR/AndroidRuntime(825): at com.tmall.htc.manage.Config.getname(Config.java:384)02-07 23:19:47.221: ERROR/AndroidRuntime(825): at com.tmall.htc.manage.Config.setSummary(Config.java:150)02-07 23:19:47.221: ERROR/AndroidRuntime(825): at com.tmall.htc.manage.Config.onCreate(Config.java:88)02-07 23:19:47.221: ERROR/AndroidRuntime(825): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)02-07 23:19:47.221: ERROR/AndroidRuntime(825): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)02-07 23:19:47.221: ERROR/AndroidRuntime(825): ... 11 more

?

主要错误:

02-07 23:19:47.221: ERROR/AndroidRuntime(825): Caused by: android.content.res.Resources$NotFoundException: String resource ID #0x7f070088


发生错误原因分析:

Activity部分源代码:

public String getname() {String setting = sharedPref.getString(Config.KEY_name,context.getString(R.string.def_name));return setting;} 

Eclispe并未提示R.string.def_name处出错,不存在“def_name cannot be resolved or is not a field”问题;

经反复查找,发现:因为支持国际化,在res下设置了中文和英文两套资源文件,默认资源为中文资源。

英文资源中已有

<string name="def_name">iphone4s</string> 

?

而中文资源中没有相应配置def_name。

Android虚拟机设置为默认中文,因此运行应用时找不到相应资源而报错。

解决办法:在中文资源中添加上述配置。?

热点排行