Payday Loan Payday Loan

How to cast from View to WebView in Android

I have faced a really idiot problem, and i want to share it with you.
I tried to make a very simple webview activity like below:

 
package com.demoapp;
 
import android.app.Activity;
import android.os.Bundle;
import com.demoapp.R;
import android.webkit.WebView;
public class WebView extends Activity {
 
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.webview);
		Bundle data = getIntent().getExtras();
 
		WebView webview1 = (WebView)findViewById(R.id.webView1);
 
        webview1.getSettings().setJavaScriptEnabled(true); 
        webview1.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
 
        webview1.getSettings().setBuiltInZoomControls(true);
	    webview1.setInitialScale(50);
        webview1.loadUrl(data.getString("webview")); 
 
	}
 
}

This is looking perfect, but the Eclipse dont let you compile this.
You will get error: cannot cast from View to WebView.
You need to observe that the import android.webkit.WebView; cannot be fullfiled.
WHY? Because you have setted the class name same. As you see my class name is WebView.
This generates a conflict, between imported class WebView, and your class called WebView, so just change the name of your class to something like WebView1 and you are done.

||||| 0 I Like It! |||||

One Response so far.

  1. blackfire185 says:

    Thank you for your Tip, I have the same Problem right now.


Search

Popular

Sponsors