Search code examples
androidandroid-webview

WebView example android


There is a error in mView, I need solution

package com.example.account;

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

public class WebView extends Activity {

private WebView webView;

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

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

}

}

My xml

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

Cannot cast from view to webview

WebView mView = (WebView) findViewById(R.id.webView1)

Solution

  • You are using your activity name as WebView. This name is already used by SDK API. This is the reason it is giving you error.

    To solve it, just rename your WebView.java file to some another name like MyWebView.java then your problem will surely solve.

    To safely rename your .java file, Just go to packageexplorer , select WebView.java and press F2, and give new name.