国际化开发,资源配置不完整报错 Resources$NotFoundException

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虚拟机设置为默认中文,因此运行应用时找不到相应资源而报错。

 

解决办法:在中文资源中添加相应配置。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值