2011-04-30 57 views
0

我尝试了一个webview来显示一个网页,并且我遇到了一个让我的应用程序意外停止的大问题。我尝试了很多次,但显示了同样的错误。Android的webview无法正常工作,请帮忙

的错误是 “web视图的应用程序意外停止(过程net.webview)......”

我的Java代码:

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

public class MyWebView extends Activity { 
    /** Called when the activity is first created. */ 

    WebView mWebView; 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 
     mWebView = (WebView) findViewById(R.id.webview); 
     mWebView.getSettings().setJavaScriptEnabled(true); 
     mWebView.loadUrl("http://www.google.com"); 
    } 
} 

我的XML布局:

Code: 
<?xml version="1.0" encoding="utf-8"?> 

<WebView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/webview" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
/> 

我清单文件:

Code: 
<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
     package="net.WebView" 
     android:versionCode="1" 
     android:versionName="1.0"> 
    <uses-sdk android:minSdkVersion="7" /> 
<uses-permission android:name="android.permission.INTERNET" /> 
    <application android:icon="@drawable/icon" android:label="@string/app_name"> 
     <activity android:name=".WebView" 
        android:label="@string/app_name" 
        android:theme="@android:style/Theme.NoTitleBar"> 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 
       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 

    </application> 
</manifest> 

回答

3

清单中您的活动名称是错误的。它应该是:

<activity android:name=".MyWebView" 
       android:label="@string/app_name" 
       android:theme="@android:style/Theme.NoTitleBar"> 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 
      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
    </activity> 
+0

非常感谢。你是我的救星。我花了一天的时间。假期愉快。 – lovesunset21 2011-04-30 16:57:44

+0

不客气。如果它回答你的问题,请通过点击左边的绿色勾号(我认为)来接受这个答案。 – ccheneson 2011-04-30 17:02:33

相关问题