开发者

Android: simple webview code. ERR: Unable to start Activity

开发者 https://www.devze.com 2023-02-14 19:20 出处:网络
I have following code: public class reader extends Activity { WebView mWebView; String mFilename; /** Called when the activity is first created. */

I have following code:

public class reader extends Activity {

    WebView mWebView;
    String mFilename;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        mWebView = (WebView) findViewById(R.id.开发者_如何学PythonwebView1);
        setContentView(R.layout.webview);
        mWebView.loadUrl("http://www.google.com");

     }

}

When I run this, the emulator shows "Sorry:.. mireader Stopped unexpectedly" error.. Why ?


You shouldn't call the setContentView function twice. I am guessing your onCreate method should look like:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.webview);
    mWebView = (WebView) findViewById(R.id.webView1);
    mWebView.loadUrl("http://www.google.com");

 }


Why do you have setContentView(R.layout.webview);? You already call setContentView two lines before.

And do you have the android.permission.INTERNET permission in your AndroidManifest.xml?

Also, you should attach the logcat output as that'll probably give you a callstack pointing you in the general direction of the problem.


i am suggesting you to do it again create a simple project.paste the following code your main.xml

android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" />

and in the manifest file put the line just before ending the

and run.I think nothing wrong with it.Remove your second setContView...


go to this link you can easily create your webview application.....

http://developer.android.com/resources/tutorials/views/hello-webview.html

add this in between your setcontentView and loadurl method

mWebView.getSettings().setJavaScriptEnabled(true);

0

精彩评论

暂无评论...
验证码 换一张
取 消