在 Fragmenets 中创建动态 html 内容并加载到嵌入式 webview 上,然后在 java.lang.String.indexOf(String.java:994) 处说 java.lang.NullPointerException
public class DescFragment extends Fragment {
private CordovaWebView mCordovaWebview;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View eventDescView = inflater.inflate(
R.layout.pf_fragment_event_desc_main, container, false);
eventDescView.setTag("Event Description");
mCordovaWebview = (CordovaWebView) eventDescView
.findViewById(R.id.event_detail_web_view);
mCordovaWebview.getSettings().setJavaScriptEnabled(true);
String html = "<html> <body> <p><font size=\"3\" font face=\"Arial\" style=\"font-weight:bold;\" color=\"black\">"
+ "</p>---------------------------------"
+ "</body></html>";
mCordovaWebview.loadData(html, "text/html", "UTF-8");
mCordovaWebview.setOnTouchListener(this);
}
return eventDescView;
}
public void onDestroy() {
super.onDestroy();
if (this.mCordovaWebview != null) {
this.mCordovaWebview.handleDestroy();
}
}
日志猫
FATAL EXCEPTION: main
java.lang.NullPointerException
at java.lang.String.indexOf(String.java:994)
at org.apache.cordova.CordovaWebView.loadUrlNow(CordovaWebView.java:471)
at org.apache.cordova.CordovaWebView.loadUrl(CordovaWebView.java:356)
at org.apache.cordova.CordovaWebViewClient.onPageFinished(CordovaWebViewClient.java:302)
at android.webkit.CallbackProxy.handleMessage(CallbackProxy.java:327)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4745)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
当我提供 url 但我在 loadUrl 应用程序崩溃时提供字符串格式时,相同的代码正在工作,谢谢