Hi all:

 

Please see attached the code I have written for web view..When I run the
code I get the following error every time.

 

Sorry The application WebViewDemo(process org.example.webviewdemo)has
stopped unexpectedly.Please try again.

 

Can someone help me please.

 

Thanks

..Priya

 

lakshmi_pr...@simply-logic.com

 

 

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
package org.example.webviewdemo;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnKeyListener;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.EditText;


public class WebViewDemoActivity extends Activity {
        private WebView webView;
        private EditText urlField;
        private Button search;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
     // Create reference to UI elements
        webView  = (WebView) findViewById(R.id.webview_compontent);
        webView.setWebChromeClient(new WebChromeClient());
       // webView.setWebViewClient(new HelloWebViewClient());
        webView.getSettings().setJavaScriptEnabled(true);
        webView.loadUrl("http://www.google.com/";);
        //urlField = (EditText)findViewById(R.id.url);
        
        
        // workaround so that the default browser doesn't take over
        webView.setWebViewClient(new MyWebViewClient());
        
        // Setup click listener
        search = (Button)findViewById(R.id.Search);
        search.setOnClickListener( new OnClickListener() {
                public void onClick(View view) {
                        openURL();
                }
        });
        
        // Setup key listener
        urlField.setOnKeyListener( new OnKeyListener() {
                public boolean onKey(View view, int keyCode, KeyEvent event) {
                        if(keyCode==KeyEvent.KEYCODE_ENTER) {
                                openURL();
                                return true;
                        } else {
                                return false;
                        }
                }
        });
 
    }
    
    /** Opens the URL in a browser */
    private void openURL() {
        webView.loadUrl(urlField.getText().toString());
        //webView.requestFocus();
    }
    
    private class MyWebViewClient extends WebViewClient {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return true;

        }
        public void onClick(View v)
        {
        
        String url=null;
                // TODO Auto-generated method stub
        // Otherwise, the link is not for a page on my site, so launch another 
Activity that handles URLs
        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
        startActivity(intent);
        //return true;

}
}
}
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android";
      package="org.example.webviewdemo"
      android:versionCode="1"
      android:versionName="1.0">
    <uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.INTERNET" />

    <application android:icon="@drawable/icon" android:label="@string/search">
        <activity android:name=".WebViewDemoActivity"
                  android:label="@string/search">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

    </application>
</manifest>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android";
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
    
    <LinearLayout 
        android:orientation="horizontal"
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content">
  
           <TextView 
        android:text="NB" 
        android:id="@+id/textView1"
        android:textColor="#FFFFFFFF"
        android:textSize="50px"
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content">
    </TextView>
            
<Button 
      android:text="Call Us" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="bottom" 
      android:id="@+id/Call_Us">
</Button>

<Button 
      android:text="Search" 
      android:layout_width="wrap_content" 
      android:layout_gravity="bottom" 
      android:layout_height="wrap_content" 
      android:id="@+id/Search">
</Button>

<Button 
     android:text="Email Us" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="bottom" 
     android:id="@+id/Email_Us">
</Button>
          
            
</LinearLayout>


        <WebView  
                android:id="@+id/webview_compontent"
            android:layout_width="fill_parent" 
            android:layout_height="fill_parent" 
            android:layout_weight="1.0"   
        />
</LinearLayout>

Reply via email to