MapView giving error ! Please help

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

MapView giving error ! Please help

Postby zibranm » Sun Mar 07, 2010 10:56 pm

Hi,
I am trying to create an application, where the initial screen (Activity) has a button, and in response to the button press I want to display the MapView.

I have the following code:
//------------------the initial Activity Class: Main.java -----------------------------------------
public class Main extends Activity { // initial activity
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button gpsButton = (Button) findViewById(R.id.gpsButton);
gpsButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(v.getContext(), MyMapViewer.class);
startActivity(intent);
}
});
}
//-------------------------- MyMapViewer.java ---------------------------------
public class MyMapViewer extends MapActivity {
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.mapview);
}
protected boolean isRouteDisplayed() { return false; }
}

//--------------------------The manifest file: AndroidManifect.xml ---------------------------------
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="test.android"
android:versionCode="1"
android:versionName="1.0">
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />

<uses-library android:name="com.google.android.maps" />

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

<activity android:name=".MyMapViewer"
android:label="@string/my_map_viewer">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.SAMPLE_CODE" />
</intent-filter>
</activity>

</application>
<uses-sdk android:minSdkVersion="7" />
</manifest>

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

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

<com.google.android.maps.MapView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:enabled="true"
android:clickable="true"
android:apiKey="apisamples"
/>
</LinearLayout>

//------------------main.xml-----------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<Button android:id="@+id/gpsButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="GPS Location" />
</LinearLayout>
-----------------------------------------------------------------------

When I run the program, the initial screen is displayed with the button. But when I press the button, I get a popup which states, ".. the program stopped unexpectedly". The following error I extracted from logcat:

I/ActivityManager( 52): Starting activity: Intent { cmp=test.android/.MyMapViewer }
D/AndroidRuntime( 236): Shutting down VM
W/dalvikvm( 236): threadid=3: thread exiting with uncaught exception (group=0x4001b188)
E/AndroidRuntime( 236): Uncaught handler: thread main exiting due to uncaught exception
E/AndroidRuntime( 236): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{test.android/test.android.MyMapViewer}: java.lang.RuntimeException: stub
E/AndroidRuntime( 236): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2417)
E/AndroidRuntime( 236): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
E/AndroidRuntime( 236): at android.app.ActivityThread.access$2200(ActivityThread.java:119)
E/AndroidRuntime( 236): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
E/AndroidRuntime( 236): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 236): at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime( 236): at android.app.ActivityThread.main(ActivityThread.java:4363)
E/AndroidRuntime( 236): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 236): at java.lang.reflect.Method.invoke(Method.java:521)
E/AndroidRuntime( 236): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
E/AndroidRuntime( 236): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
E/AndroidRuntime( 236): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime( 236): Caused by: java.lang.RuntimeException: stub
E/AndroidRuntime( 236): at com.google.android.maps.MapActivity.<init>(Unknown Source)
E/AndroidRuntime( 236): at test.android.MyMapViewer.<init>(MyMapViewer.java:8)
E/AndroidRuntime( 236): at java.lang.Class.newInstanceImpl(Native Method)
E/AndroidRuntime( 236): at java.lang.Class.newInstance(Class.java:1479)
E/AndroidRuntime( 236): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
E/AndroidRuntime( 236): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2409)

But when I remove the <com.google.android.maps.MapView.. .. /> from the mapview.xml, the programs runs without error. Please help me to understand and correct what I am doing wrong in using the MapView. (I have been able to display MapView when I have it on the initial screen (Launcher Activity). But Having the MapView in a subsequent Activity has been a problem here.

Thanks in advance.
Fahim
Fahim
zibranm
Freshman
Freshman
 
Posts: 2
Joined: Sun Mar 07, 2010 10:24 pm
Location: Canada

Top

Re: MapView giving error ! Please help

Postby VeeTee » Sun Feb 27, 2011 12:59 am

hi.... did someone get an answer ???
I have the same problem...

thanks
VeeTee
Freshman
Freshman
 
Posts: 2
Joined: Sun Feb 27, 2011 12:58 am

Re: MapView giving error ! Please help

Postby Harsh » Wed Mar 09, 2011 10:41 am

From first look it is observed that there is problem in your manifest file..
Below line should be child of application.
<uses-library android:name="com.google.android.maps" />
cut paste it and put it under application and it will solve.
Harsh
Once Poster
Once Poster
 
Posts: 1
Joined: Thu Feb 05, 2009 3:29 pm

Top

Return to Map Problems

Who is online

Users browsing this forum: No registered users and 3 guests