0

我无法访问 strings.xml:

Log.i("url",context.getString(R.string.url));

在字符串.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)
4

2 回答 2

1

尝试从中获取字符串Strings.xml

String strurl=context.getresources().getString(R.string.url);
Log.i("url ",strurl);
于 2012-12-12T15:53:02.607 回答
0

context显然null,如果你NullPointerException在那条线上得到一个。

于 2012-12-12T15:05:24.593 回答