無法存取到的strings.xml I:WebViewCoreThread例外訪問的strings.xml
Log.i("url",context.getString(R.string.url));
在strings.xml中
<string name="url">http://myip.com/</string>
它會產生一個異常:
12-12 14:52:44.551: E/AndroidRuntime(3534): FATAL EXCEPTION: WebViewCoreThread
12-12 14:52:44.551: E/AndroidRuntime(3534): java.lang.NullPointerException
12-12 14:52:44.551: E/AndroidRuntime(3534): at com.usualbike.cbike.NewIncidence.noRegInsertData(NewIncidence.java:70)
12-12 14:52:44.551: E/AndroidRuntime(3534): at com.usualbike.cbike.IncidenceData$MyJavaScriptInterface.enviarIncidencia(IncidenceData.java:163)
12-12 14:52:44.551: E/AndroidRuntime(3534): at android.webkit.WebViewCore.nativeTouchUp(Native Method)
12-12 14:52:44.551: E/AndroidRuntime(3534): at android.webkit.WebViewCore.nativeTouchUp(Native Method)
12-12 14:52:44.551: E/AndroidRuntime(3534): at android.webkit.WebViewCore.access$3300(WebViewCore.java:52)
12-12 14:52:44.551: E/AndroidRuntime(3534): at android.webkit.WebViewCore$EventHub$1.handleMessage(WebViewCore.java:1150)
12-12 14:52:44.551: E/AndroidRuntime(3534): at android.os.Handler.dispatchMessage(Handler.java:99)
12-12 14:52:44.551: E/AndroidRuntime(3534): at android.os.Looper.loop(Looper.java:123)
12-12 14:52:44.551: E/AndroidRuntime(3534): at android.webkit.WebViewCore$WebCoreThread.run(WebViewCore.java:621)
12-12 14:52:44.551: E/AndroidRuntime(3534): at java.lang.Thread.run(Thread.java:1096)
獲取字符串,你也可以嘗試as' getResources()的getString(R.string.url);' –
我不能。此課程不擴展活動 – user1256477
哦!我的意思是'context.getresources()。getString(R.string.url);'也使用非活動類的構造函數來初始化上下文變量而不是靜態的 –