Issue
I am trying out a very simple webview
application on Android. While the program builds OK, there are run-time errors that I cannot decode. The layout:
<?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"
/>
The code:
/* 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;
}
}
The error observed:
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
I have come across similar errors that detail OutOfMemoryExceptions in large projects, but since the above code is all there is to the project, this does not seem a likely explanation.
Solution
There is typo mistake in your layout: WebView need to be written in CamelCase. There isn't such view as 'Webview'. So your layout should look as:
<?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" />
Answered By - andrew
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.