1

小さなアプリでズーム コントロールを動作させようとしています。以下のコードを起動すると、アプリがエミュレーターでクラッシュします (Google API を使用する Android 2.3.3)。コメントアウトすると:

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;
 }
}

Androidマニフェスト

<?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>
4

1 に答える 1

0

あなたのコードを新しいプロジェクトに取り込んだところ、問題が見つかりました。

この行:

android.id="@+id/mymapView"

する必要があります

android:id="@+id/mymapView"

ドットとコロンに注意してください。

そのため、findViewById が null を返す原因となっていたため、myMapView.setBuiltInZoomControls() は segfaulting でした。

于 2012-01-28T00:33:20.363 に答える