displaying map on click of a button(with codes)

Put problem concerning MapActivities, MapViews, Overlays and GPS in this forum.

displaying map on click of a button(with codes)

Postby schofeild » Sat Mar 05, 2011 1:28 pm

hey guys i want to display a map on the click of a button...for this i have implemented 2 classes
one class has a button and an intent call,while the second class displays the map.On running the application the button is getting displayed but on clicking it the application crashes.

onclick.java(first class)
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. import android.app.Activity;
  2. import android.os.Bundle;
  3. import android.view.*;
  4. import android.widget.*;
  5. import android.content.Intent;
  6.  
  7. public class onclick extends Activity
  8. {
  9.     /** Called when the activity is first created. */
  10.     @Override
  11.     public void onCreate(Bundle savedInstanceState) {
  12.         super.onCreate(savedInstanceState);
  13.         setContentView(R.layout.main);
  14.         Button btnOpen = (Button) findViewById(R.id.btnSave);
  15.         btnOpen.setOnClickListener(new View.OnClickListener() {
  16.             public void onClick(View v) {
  17.                // TODO Auto-generated method stub
  18.                Intent myIntent=new Intent(onclick.this,a.class);
  19.                startActivity(myIntent);
  20.                
  21.             }
  22.          });
  23.     }
  24. }
Parsed in 0.034 seconds, using GeSHi 1.0.8.4



main.xml
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3.    android:orientation="vertical"
  4.    android:layout_width="fill_parent"
  5.    android:layout_height="fill_parent"
  6.    >
  7. <Button android:id="@+id/btnSave"
  8.        android:layout_width="fill_parent"
  9.        android:layout_height="wrap_content"
  10.        android:text="SHOW MAP"
  11.        />
  12. </LinearLayout>
  13.  
Parsed in 0.002 seconds, using GeSHi 1.0.8.4


a.java
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package com.onclick;
  2.  
  3. import android.os.Bundle;
  4. import com.google.android.maps.*;
  5.  
  6.  
  7.  
  8. public class a extends MapActivity{
  9.    private MapView mapView;
  10.  
  11.    
  12.    @Override
  13.    protected boolean isRouteDisplayed() {
  14.       // TODO Auto-generated method stub
  15.       return false;
  16.    }
  17.    @Override
  18.    public void onCreate(Bundle savedInstanceState) {
  19.    super.onCreate(savedInstanceState);
  20.    setContentView(R.layout.f);
  21.    mapView = (MapView)findViewById(R.id.map_view);
  22.    mapView.setStreetView(true);
  23.    }
  24.    
  25.    }
Parsed in 0.032 seconds, using GeSHi 1.0.8.4


f.xml
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3.    android:orientation="vertical"
  4.    android:layout_width="fill_parent"
  5.    android:layout_height="fill_parent"
  6.    >
  7. <com.google.android.maps.MapView
  8.        android:id="@+id/map_view"
  9.        android:layout_width="fill_parent"
  10.        android:layout_height="fill_parent"
  11.        android:enabled="true"
  12.        android:clickable="true"
  13.        android:apiKey="0Ems9fSTa3ywDKShXwf2bntf3MsBTIJ0ARwahVA"
  14.        />
  15.        
  16.         </LinearLayout>
Parsed in 0.002 seconds, using GeSHi 1.0.8.4


AndroidManifest.xml
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <manifest xmlns:android="http://schemas.android.com/apk/res/android"
  3.      package="com.onclick"
  4.      android:versionCode="1"
  5.      android:versionName="1.0">
  6.     <uses-sdk android:minSdkVersion="7" />
  7.         <uses-library android:name="com.google.android.maps" />
  8.     <application android:icon="@drawable/icon" android:label="@string/app_name">
  9.         <activity android:name=".onclick"
  10.                  android:label="@string/app_name">
  11.             <intent-filter>
  12.                 <action android:name="android.intent.action.MAIN" />
  13.                 <category android:name="android.intent.category.LAUNCHER" />
  14.             </intent-filter>
  15.         </activity>
  16.         <activity android:name=".a"></activity>
  17.        
  18.     </application>
  19.     <uses-permission
  20.        android:name="android.permission.ACCESS_COARSE_LOCATION" />
  21.     <uses-permission
  22.        android:name="android.permission.ACCESS_FINE_LOCATION" />
  23.     <uses-permission android:name="android.permission.INTERNET" />
  24. </manifest>
Parsed in 0.004 seconds, using GeSHi 1.0.8.4



guys plzz help me out...any help will be really appreciated :)
schofeild
Developer
Developer
 
Posts: 40
Joined: Wed Jul 21, 2010 12:08 pm

Top

Re: displaying map on click of a button(with codes)

Postby schofeild » Sun Mar 06, 2011 12:04 pm

logcat error:

16:22:41.812: ERROR/AndroidRuntime(219): Uncaught handler: thread main exiting due to uncaught exception

03-06 16:22:41.883: ERROR/AndroidRuntime(219): java.lang.NoClassDefFoundError: com.onclick.a

03-06 16:22:41.883: ERROR/AndroidRuntime(219):at com.onclick.onclick$1.onClick(onclick.java:22)

03-06 16:22:41.883: ERROR/AndroidRuntime(219):at android.view.View.performClick(View.java:2364)

03-06 16:22:41.883: ERROR/AndroidRuntime(219)at android.view.View.onTouchEvent(View.java:4179) 03-06 16:22:41.883: ERROR/AndroidRuntime(219): at android.widget.TextView.onTouchEvent(TextView.java:6540)

03-06 16:22:41.883: ERROR/AndroidRuntime(219): at android.view.View.dispatchTouchEvent(View.java:3709)

03-06 16:22:41.883: ERROR/AndroidRuntime(219):at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)

03-06 16:22:41.883: ERROR/AndroidRuntime(219): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)

03-06 16:22:41.883: ERROR/AndroidRuntime(219):at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)

03-06 16:22:41.883: ERROR/AndroidRuntime(219):at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)

03-06 16:22:41.883: ERROR/AndroidRuntime(219):at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1659)

03-06 16:22:41.883: ERROR/AndroidRuntime(219):at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1107)

03-06 16:22:41.883: ERROR/AndroidRuntime(219):at android.app.Activity.dispatchTouchEvent(Activity.java:2061)

03-06 16:22:41.883: ERROR/AndroidRuntime(219):at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1643)

03-06 16:22:41.883: ERROR/AndroidRuntime(219): at android.view.ViewRoot.handleMessage(ViewRoot.java:1691)

03-06 16:22:41.883: ERROR/AndroidRuntime(219): at android.os.Handler.dispatchMessage(Handler.java:99)

03-06 16:22:41.883: ERROR/AndroidRuntime(219): at android.os.Looper.loop(Looper.java:123)

03-06 16:22:41.883: ERROR/AndroidRuntime(219): at android.app.ActivityThread.main(ActivityThread.java:4363)

03-06 16:22:41.883: ERROR/AndroidRuntime(219): at java.lang.reflect.Method.invokeNative(Native Method)

03-06 16:22:41.883: ERROR/AndroidRuntime(219):at java.lang.reflect.Method.invoke(Method.java:521)

03-06 16:22:41.883: ERROR/AndroidRuntime(219): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)

03-06 16:22:41.883: ERROR/AndroidRuntime(219):at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)

03-06 16:22:41.883: ERROR/AndroidRuntime(219):at dalvik.system.NativeStart.main(Native Method)
schofeild
Developer
Developer
 
Posts: 40
Joined: Wed Jul 21, 2010 12:08 pm

Top

Return to Map Problems

Who is online

Users browsing this forum: No registered users and 2 guests