我想获取我的应用程序的版本号,但是当我尝试它时应用程序在加载时崩溃。
int currentVersionCode;
try {
currentVersionCode = this.getPackageManager().getPackageInfo(
this.getApplicationInfo().packageName, 0).versionCode;
Toast.makeText(this, currentVersionCode, Toast.LENGTH_SHORT).show();
} catch (NameNotFoundException e) {
return;
}
日志猫:
04-05 16:01:43.108: D/LocationManager(1109): Constructor: service = android.location.ILocationManager$Stub$Proxy@44c0f748
04-05 16:01:43.198: W/ResourceType(1109): No package identifier when getting name for resource number 0x00000001
04-05 16:01:43.208: D/AndroidRuntime(1109): Shutting down VM
04-05 16:01:43.208: W/dalvikvm(1109): threadid=3: thread exiting with uncaught exception (group=0x4001b188)
04-05 16:01:43.208: E/AndroidRuntime(1109): Uncaught handler: thread main exiting due to uncaught exception
04-05 16:01:43.228: E/AndroidRuntime(1109): java.lang.RuntimeException: Unable to start activity ComponentInfo{weather.right.now/weather.right.nowActivity}: android.content.res.Resources$NotFoundException: String resource ID #0x1
04-05 16:01:43.228: E/AndroidRuntime(1109): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2496)
04-05 16:01:43.228: E/AndroidRuntime(1109): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
04-05 16:01:43.228: E/AndroidRuntime(1109): at android.app.ActivityThread.access$2200(ActivityThread.java:119)
04-05 16:01:43.228: E/AndroidRuntime(1109): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
04-05 16:01:43.228: E/AndroidRuntime(1109): at android.os.Handler.dispatchMessage(Handler.java:99)
04-05 16:01:43.228: E/AndroidRuntime(1109): at android.os.Looper.loop(Looper.java:123)
04-05 16:01:43.228: E/AndroidRuntime(1109): at android.app.ActivityThread.main(ActivityThread.java:4363)
04-05 16:01:43.228: E/AndroidRuntime(1109): at java.lang.reflect.Method.invokeNative(Native Method)
04-05 16:01:43.228: E/AndroidRuntime(1109): at java.lang.reflect.Method.invoke(Method.java:521)
04-05 16:01:43.228: E/AndroidRuntime(1109): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
04-05 16:01:43.228: E/AndroidRuntime(1109): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
04-05 16:01:43.228: E/AndroidRuntime(1109): at dalvik.system.NativeStart.main(Native Method)
04-05 16:01:43.228: E/AndroidRuntime(1109): Caused by: android.content.res.Resources$NotFoundException: String resource ID #0x1
04-05 16:01:43.228: E/AndroidRuntime(1109): at android.content.res.Resources.getText(Resources.java:200)
04-05 16:01:43.228: E/AndroidRuntime(1109): at android.widget.Toast.makeText(Toast.java:258)
04-05 16:01:43.228: E/AndroidRuntime(1109): at weather.right.nowActivity.onCreate(nowActivity.java:58)
04-05 16:01:43.228: E/AndroidRuntime(1109): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-05 16:01:43.228: E/AndroidRuntime(1109): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
04-05 16:01:43.228: E/AndroidRuntime(1109): ... 11 more
04-05 16:01:43.248: I/dalvikvm(1109): threadid=7: reacting to signal 3
04-05 16:01:43.258: I/dalvikvm(1109): Wrote stack trace to '/data/anr/traces.txt'
我该如何解决我的问题?
提前致谢。