views:

678

answers:

5

Trying to create a WebView but it only shows a blank/white page. I have followed several examples and they all say that work with this code...

Here is my code:

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

public class PostenWebView extends Activity {

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.web_view);
        WebView webview = (WebView)findViewById(R.id.webview);
        webview.loadUrl("http://www.google.com");
    }
}

And here is the web_view.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/webview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
    />
</LinearLayout>
+1  A: 

You have to add the permission to your AndroidManifest.xml file.

<uses-permission
        android:name="android.permission.INTERNET"></uses-permission>
Pentium10
Alreade done that... I use internet in several other activities in my application and they are working just fine, so that can't be what's making it show a blank page... :/
Sara
I don't know anything else other than this. Make sure you have 3G icon the taskbar. If you do this in emulator restart it a couple of times to get it there.
Pentium10
A: 

You need to enable Javascript (.getSettings().setJavaScriptEnabled(true)), or choose a Web page that does not rely upon Javascript.

CommonsWare
A: 

I found an example that finally worked! :)

http://code.google.com/p/apps-for-android/source/browse/trunk/Samples/WebViewDemo/src/com/google/android/webviewdemo/WebViewDemo.java

But the problem was also with the URL, when I tried to go to google.com through my WebView in instantly opened my ordinary browser on my phone... But other URL's worked just fine :)

Sara
A: 

I don't know about other phones, but on HTC HERO i have similar problem: after i disable mobile internet and enable wifi, webview doesn't display, although other internet activities like httpget in the same application work without any problems. No errors are shown in the logs...

saulius
A: 

You might be getting redirected.. just install a webviewclient allong with you web view :)

Abhinava