这是我的 strings.xml
<resources>
<string name="alert_internet">out</string>
</resources>
我试图在我的主要活动中调用这个字符串,如下所示:
final String net = getString(R.string.alert_internet);
我也检查了我的 R.java 文件,'alert_internet' 的 int 存在。但是由于某种原因,每当我启动应用程序时,它都会崩溃。试图得到一个简单的字符串我做错了什么?
这是我的 log.cat
09-23 13:17:33.092: E/AndroidRuntime(21302): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1573)
09-23 13:17:33.092: E/AndroidRuntime(21302): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
09-23 13:17:33.092: E/AndroidRuntime(21302): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
09-23 13:17:33.092: E/AndroidRuntime(21302): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
09-23 13:17:33.092: E/AndroidRuntime(21302): at android.os.Handler.dispatchMessage(Handler.java:99)
09-23 13:17:33.092: E/AndroidRuntime(21302): at android.os.Looper.loop(Looper.java:130)
09-23 13:17:33.092: E/AndroidRuntime(21302): at android.app.ActivityThread.main(ActivityThread.java:3693)
09-23 13:17:33.092: E/AndroidRuntime(21302): at java.lang.reflect.Method.invokeNative(Native Method)
09-23 13:17:33.092: E/AndroidRuntime(21302): at java.lang.reflect.Method.invoke(Method.java:507)
09-23 13:17:33.092: E/AndroidRuntime(21302): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:907)
09-23 13:17:33.092: E/AndroidRuntime(21302): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:665)
09-23 13:17:33.092: E/AndroidRuntime(21302): at dalvik.system.NativeStart.main(Native Method)
09-23 13:17:33.092: E/AndroidRuntime(21302): Caused by: java.lang.NullPointerException
09-23 13:17:33.092: E/AndroidRuntime(21302): at android.content.ContextWrapper.getResources(ContextWrapper.java:80)
09-23 13:17:33.092: E/AndroidRuntime(21302): at android.content.Context.getString(Context.java:183)
09-23 13:17:33.092: E/AndroidRuntime(21302): at com.akilli.ticaret.Main.<init>(Main.java:25)
09-23 13:17:33.092: E/AndroidRuntime(21302): at java.lang.Class.newInstanceImpl(Native Method)
09-23 13:17:33.092: E/AndroidRuntime(21302): at java.lang.Class.newInstance(Class.java:1409)
09-23 13:17:33.092: E/AndroidRuntime(21302): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
09-23 13:17:33.092: E/AndroidRuntime(21302): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1565)
09-23 13:17:33.092: E/AndroidRuntime(21302): ... 11 more
09-23 13:17:33.102: E/(179): Dumpstate > /data/log/dumpstate_app_error