2011-04-30 56 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

相關問題