1

I'm trying to get the zoom controls to work on my small app. When I launch the code below the App crashes in the Emulator (Android 2.3.3 using Google API). When I comment out:

myMapView.setBuiltInZoomControls(false);

It will launch and show me the map zoomed out all the way. Any ideas on what I am doing wrong?

Thanks!

MainActivity.java

public class MainActivity extends MapActivity {
MapView myMapView;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    myMapView = (MapView) findViewById(R.id.mymapView);
    myMapView.setBuiltInZoomControls(true);
}



@Override
 protected boolean isRouteDisplayed() {
    return false;
 }
}

AndroidManifest

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="net.learn2develop.LBS"
android:versionCode="1"
android:versionName="1.0" >




<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name" >
<uses-library android:name="com.google.android.maps"/>
    <activity
        android:label="@string/app_name"
        android:name=".MainActivity" 
        >
        <intent-filter >
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>
<uses-sdk android:minSdkVersion="10" />
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
</manifest>

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" >

<com.google.android.maps.MapView
    android.id="@+id/mymapView"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:enabled="true"
    android:clickable="true"
    android:apiKey="KEY_HERE"/> 
</LinearLayout>
glory102
  • 11
  • 1
  • Don't make us guess - add the stack trace which probably has the explicit answer to your question. – BitBank Jan 28 '12 at 00:04

1 Answers1

0

I pulled your code into a new project and found the problem.

This line:

android.id="@+id/mymapView"

Should be

android:id="@+id/mymapView"

Notice the dot versus the colon!

So this was causing findViewById to return null and thus myMapView.setBuiltInZoomControls() was segfaulting.

mborsuk
  • 1,306
  • 1
  • 8
  • 4