调试webview,总是提示:web page not available。用了一个最简单的代码,还是提示同样的错误。
代码如下:
------------------------------------------------------------
XML code
<?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"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<android.webkit.WebView android:id="@+id/webView1" android:layout_width="fill_parent" android:layout_height="fill_parent"></android.webkit.WebView>
</LinearLayout>
Java code
public class ViewtestActivity extends Activity {
private WebView webview;
private String url = "http://www.baidu.com/";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
webview = (WebView) findViewById(R.id.webView1);
fillWebView(url);
}
private void fillWebView(String url) {
WebSettings webSettings = webview.getSettings();
webSettings.setSavePassword(false);
webSettings.setSaveFormData(false);
webSettings.setJavaScriptEnabled(true);
webSettings.setSupportZoom(false);
webview.setWebChromeClient(new WebChromeClient());
webview.loadUrl(url);
}
}
AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="viewtest.x"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="4" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission>
<uses-permission android:name="android.permission.READ_PHONE_STATE"></uses-permission>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"></uses-permission>
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".ViewtestActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
------解决方案--------------------
顶一下
------解决方案--------------------
用你的代码试了一下,完全ok啊,估计是环境问题。