0
我做了一個webview活動,它會在加載網頁後崩潰(有時顯示不幸的是,stopeed somtime不顯示任何東西只是關閉了應用程序)。使用android web視圖獲取vm中止錯誤
這是我的代碼和logcat。請幫忙。
的logcat:
04-02 11:43:27.708: E/dalvikvm(32517): VM aborting
04-02 11:43:27.709: A/libc(32517): Fatal signal 11 (SIGSEGV) at 0xdeadd00d (code=1), thread 32546 (WebViewCoreThre)
MainActivity.java
package com.example.mywebview;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.EditText;
public class MainActivity extends Activity {
private EditText field;
private WebView browser;
String url;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
field = (EditText) findViewById(R.id.urlField);
browser = (WebView) findViewById(R.id.webView1);
browser.setWebViewClient(new MyBrowser());
}
public void open(View view) {
url = field.getText().toString();
if (url.startsWith("http://")) {
} else {
url = "http://" + url;
}
browser.getSettings().setLoadsImagesAutomatically(true);
browser.getSettings().setJavaScriptEnabled(true);
browser.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
browser.loadUrl(url);
}
private class MyBrowser extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}
}
activity_main.xml中
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
<EditText
android:id="@+id/urlField"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/textView1"
android:layout_centerHorizontal="true"
android:ems="10" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/urlField"
android:layout_centerHorizontal="true"
android:onClick="open"
android:text="@string/browse" />
<WebView
android:id="@+id/webView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView1"
android:layout_alignParentBottom="true"
android:layout_below="@+id/button1" />
</RelativeLayout>