Android的web视图的NullPointerException [英] Android Webview NullPointerException
本文介绍了Android的web视图的NullPointerException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
什么是当我遇到网页视图的NullPointerException异常可能的错误:
What are possible error when I encountered the NullPointerException for Webview:
WebView webView;
webView = (WebView) findViewById(R.id.webView3);
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl("...");
这是我的webview3.xml:
This is my webview3.xml:
<?xml version="1.0" encoding="utf-8"?>
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/webView3"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
NPE上线 webView.getSettings()setJavaScriptEnabled(真);
推荐答案
试试这个样本code,
Try this sample code,
RES /布局/ webview3.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<WebView
android:id="@+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</LinearLayout>
在
设置权限的的AndroidManifest.xml 文件
<uses-permission android:name="android.permission.INTERNET" />
而在你的的onCreate()
方法使用code。
setContentView(R.layout.webview3.xml);
WebView mywebview = (WebView) findViewById(R.id.webview);
mywebview.loadUrl("http://Enter your URL here");
WebSettings webSettings = mywebview.getSettings();
webSettings.setJavaScriptEnabled(true);
这篇关于Android的web视图的NullPointerException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文