Alex Rivera | Logout

Android - WebView = Web page not available

Asked 2011-09-14T21:42:48.303
23

When using a WebView view in my app, no matter what page I force it to visit, it says Web page not found. Here is my code:

MainActivity.java

package com.testing.webview;

import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebSettings;
import android.webkit.WebView;

public class MainActivity extends Activity
{
    @Override
    public void onCreate( Bundle savedInstanceState )
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        WebView webView = (WebView) findViewById(R.id.webView1);
        WebSettings webSettings = webView.getSettings();
        webSettings.setBuiltInZoomControls(true);
        webView.loadUrl("http://www.google.com");        
    }
}

main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical">
    <WebView
        android:id="@+id/webView1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" />                
</LinearLayout>

It's very basic code as you can see. There is indeed an internet connection as I can open the normal Browser app and visit any webpage like normal.

Edit
Report

1 Answer

59

Are you using the correct Internet permission?

<uses-permission android:name="android.permission.INTERNET"></uses-permission>
answered 2011-09-14T21:46:16.060

Your Answer