2013-03-24 67 views
0

我嘗試了一個非常簡單的webview應用程序在Android上。雖然程序構建正常,但仍有運行時錯誤,我無法解碼。佈局:使用基本webview的錯誤 - Android

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

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

代碼:

/* Program to create sample webview. 
* Steps: 
* 1. Create webview. 
* 2. Show some website in it. 
* 3. Show some transitions as well. 
*/ 

package com.sriram.hellowebview; 

import android.app.Activity; 
import android.os.Bundle; 
import android.util.Log; 
import android.view.Menu; 
import android.webkit.WebView; 

public class helloWebview extends Activity { 

    WebView myWebview; 
    String url = "http://www.google.com"; 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_hello_webview); 

     Log.v(this.toString(), "Starting activity."); 

     myWebview = (WebView) findViewById(R.id.helloWebview); 

     Log.v(this.toString(), "Getting settings."); 
     //myWebview.getSettings().setJavaScriptEnabled(true); 

     Log.v(this.toString(), "Loading URL now."); 
     myWebview.loadUrl(url); 
     Log.v(this.toString(), "Loaded URL."); 

     //open all links within the same webview. 
     //myWebview.setWebViewClient(new WebViewClient()); 
     //Log.v(this.toString(), "All done here."); 
    } 

    @Override 
    public boolean onCreateOptionsMenu(Menu menu) { 
     getMenuInflater().inflate(R.menu.activity_hello_webview, menu); 
     return true; 
    } 
} 

錯誤觀察:

03-24 14:48:27.618: E/AndroidRuntime(388): Uncaught handler: thread main exiting due to uncaught exception 
03-24 14:48:27.658: E/AndroidRuntime(388): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.sriram.hellowebview/com.sriram.hellowebview.helloWebview}: android.view.InflateException: Binary XML file line #3: Error inflating class Webview 

我也碰到過類似的錯誤,在大項目詳細OutOfMemoryExceptions,但由於上面的代碼所有這些都是項目,這似乎不是一個可能的解釋。

回答

3

佈局中存在拼寫錯誤:需要使用CamelCase編寫WebView。沒有像'Webview'這樣的觀點。所以你的佈局應該看起來如下:

<?xml version="1.0" encoding="utf-8"?> 
<WebView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/helloWebview" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" /> 
2

您正在收到此錯誤消息,因爲您沒有任何父視圖佈局。

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

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    /> 

    <WebView 
     android:id="@+id/helloWebview" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
    /> 

希望它能幫助:

作爲

修改XML文件。