0

私はwebviewAndroidで非常にシンプルなアプリケーションを試しています。プログラムは正常にビルドされますが、デコードできない実行時エラーがあります。レイアウト:

<?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の詳細を示す同様のエラーに遭遇しましたが、プロジェクトには上記のコードがすべて含まれているため、これはおそらく説明ではないようです。

4

2 に答える 2

3

レイアウトにタイプミスがあります。WebViewはCamelCaseで作成する必要があります。'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" />
于 2013-03-24T09:35:08.460 に答える
2

Webviewの親レイアウトがないため、このエラーが発生します。

xmlファイルを次のように変更します。

<?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"
     />  

それが役に立てば幸い。

于 2013-03-24T09:33:34.420 に答える