Android 2.3.3 Eclipse Version: 3.7.0 LogCat
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: main
02-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 #0x7f070088
02-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 #0x7f070088
02-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虚拟机设置为默认中文,因此运行应用时找不到相应资源而报错。
解决办法:在中文资源中添加上述配置。
沒有將切换的activity加入AndroidManifest.xml,导致source not found错误
Android Styles & Themes(上)——Style Android Styles & Themes(下)——Theme
Android应用开发——系统自带样式Android:theme
•android:theme="@android:style/Theme.Dialog"
将一个Activity显示为能话框模式
•android:theme="@android:style/Theme.NoTitleBar"
不显示应用程序标题栏
•android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
不显示应用程序标题栏,并全屏
•android:theme="Theme.Light"
背景为白色
•android:theme="Theme.Light.NoTitleBar"
白色背景并无标题栏
•android:theme="Theme.Light.NoTitleBar.Fullscreen"
白色背景,无标题栏,全屏
•android:theme="Theme.Black"
背景黑色
•android:theme="Theme.Black.NoTitleBar"
黑色背景并无标题栏
•android:theme="Theme.Black.NoTitleBar.Fullscreen"
黑色背景,无标题栏,全屏
•android:theme="Theme.Wallpaper"
用系统桌面为应用程序背景
•android:theme="Theme.Wallpaper.NoTitleBar"
用系统桌面为应用程序背景,且无标题栏
•android:theme="Theme.Wallpaper.NoTitleBar.Fullscreen"
用系统桌面为应用程序背景,无标题栏,全屏
•android:theme="Translucent"
•android:theme="Theme.Translucent.NoTitleBar"
•android:theme="Theme.Translucent.NoTitleBar.Fullscreen"
•android:theme="Theme.Panel"
•android:theme="Theme.Light.Panel"
-----------------------
样式使用相关使用图示