mapview is the id of your RelativeLayout, which contains your MapView, but it not a MapView itself.
On Sep 22, 1:21 pm, Lex <[email protected]> wrote: > ...I really don't understand how something this simple (and I have > done it before) doesn't work. I'm pretty sure it will turn out that I > am missing something obvious. > > I just created a MapView, all it does is show the map and when I > allocate mapView to it's layout, there's a ClassCastException: > > import com.google.android.maps.MapActivity; > import com.google.android.maps.MapView; > > import android.app.Activity; > import android.os.Bundle; > > public class PPMMap extends MapActivity { > > public MapView mapView; > > /** Called when the activity is first created. */ > @Override > public void onCreate(Bundle savedInstanceState) { > super.onCreate(savedInstanceState); > setContentView(R.layout.main); > > mapView = (MapView) findViewById(R.id.mapview); // THROWS > CLASSCASTEXCEPTION > mapView.setBuiltInZoomControls(true); > > } > > @Override > protected boolean isRouteDisplayed() { > // TODO Auto-generated method stub > return false; > } > > } > > <?xml version="1.0" encoding="utf-8"?> > > <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/ > android" > android:id="@+id/mapview" > android:orientation="vertical" > 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:apiKey="****************" > /> > > </RelativeLayout> > > 09-22 17:16:03.676: ERROR/AndroidRuntime(730): > java.lang.RuntimeException: Unable to start activity ComponentInfo > {....patyo.PPMMap}: java.lang.ClassCastException: > android.widget.RelativeLayout > 09-22 17:16:03.676: ERROR/AndroidRuntime(730): at > android.app.ActivityThread.performLaunchActivity(ActivityThread.java: > 2268) > 09-22 17:16:03.676: ERROR/AndroidRuntime(730): at > android.app.ActivityThread.handleLaunchActivity(ActivityThread.java: > 2284) > 09-22 17:16:03.676: ERROR/AndroidRuntime(730): at > android.app.ActivityThread.access$1800(ActivityThread.java:112) > 09-22 17:16:03.676: ERROR/AndroidRuntime(730): at > android.app.ActivityThread$H.handleMessage(ActivityThread.java:1692) > 09-22 17:16:03.676: ERROR/AndroidRuntime(730): at > android.os.Handler.dispatchMessage(Handler.java:99) > 09-22 17:16:03.676: ERROR/AndroidRuntime(730): at > android.os.Looper.loop(Looper.java:123) > 09-22 17:16:03.676: ERROR/AndroidRuntime(730): at > android.app.ActivityThread.main(ActivityThread.java:3948) > 09-22 17:16:03.676: ERROR/AndroidRuntime(730): at > java.lang.reflect.Method.invokeNative(Native Method) > 09-22 17:16:03.676: ERROR/AndroidRuntime(730): at > java.lang.reflect.Method.invoke(Method.java:521) > 09-22 17:16:03.676: ERROR/AndroidRuntime(730): at > com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run > (ZygoteInit.java:782) > 09-22 17:16:03.676: ERROR/AndroidRuntime(730): at > com.android.internal.os.ZygoteInit.main(ZygoteInit.java:540) > 09-22 17:16:03.676: ERROR/AndroidRuntime(730): at > dalvik.system.NativeStart.main(Native Method) > 09-22 17:16:03.676: ERROR/AndroidRuntime(730): Caused by: > java.lang.ClassCastException: android.widget.RelativeLayout > 09-22 17:16:03.676: ERROR/AndroidRuntime(730): > at ....PPMMap.onCreate(PPMMap.java:21) > 09-22 17:16:03.676: ERROR/AndroidRuntime(730): at > android.app.Instrumentation.callActivityOnCreate(Instrumentation.java: > 1123) > 09-22 17:16:03.676: ERROR/AndroidRuntime(730): at > android.app.ActivityThread.performLaunchActivity(ActivityThread.java: > 2231) > > Call me an idiot, but I just don't get it. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~----------~----~----~----~------~----~------~--~---

