set Встроенный Zoom Controls вылетает приложение эмулятора

1

Я пытаюсь заставить элементы управления увеличением работать в моем маленьком приложении. Когда я запускаю код ниже, приложение падает в эмуляторе (Android 2.3.3 с использованием Google API). Когда я прокомментирую:

myMapView.setBuiltInZoomControls(false);

Он запустится и покажет мне, что карта полностью изменилась. Любые идеи о том, что я делаю неправильно?

Благодарю!

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>
  • 0
    Не заставляйте нас гадать - добавьте трассировку стека, которая, вероятно, имеет четкий ответ на ваш вопрос.
Теги:

1 ответ

0

Я вытащил ваш код в новый проект и нашел проблему.

Эта строка:

android.id="@+id/mymapView"

Должно быть

android:id="@+id/mymapView"

Обратите внимание на точку в зависимости от толстой кишки!

Таким образом, это заставило findViewById возвращать значение null, и поэтому myMapView.setBuiltInZoomControls() был segfault.

Ещё вопросы

Сообщество Overcoder
Наверх
Меню