Приложение падает, когда оно достигает myMapView.getController () - PullRequest
0 голосов
/ 04 июня 2011

По какой-то причине эта ОЧЕНЬ простая программа падает, когда достигает метода getController (). Это почти как отладчик, который пытается сказать мне что-то, но это все искажено. Но это определенно взрывается на этой линии. Если я возьму это из кода, приложение запустит основную карту. Я перепробовал все мыслимые и не могу понять проблему. У кого-нибудь есть мысли? Заранее спасибо.

открытый класс Main extends MapActivity {

MapView myMapView;
MapController mc;
GeoPoint point;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    double lon = -79.9;
    double lat = 40.4;

    myMapView = (MapView) findViewById(R.layout.main);

    point = new GeoPoint((int) (lat * 1E6), (int) (lon * 1E6));

    mc = myMapView.getController();
    mc.animateTo(point);
    mc.setZoom(13);

}
@Override
protected boolean isRouteDisplayed() {
    // TODO Auto-generated method stub
    return false;
}

И код main.xml:

 <?xml version="1.0" encoding="utf-8"?>
 <LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    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:enabled="true" 
        android:clickable="true"
        android:apiKey="0SN6PntBTxgMIeekPQm2Of1gnlDiHmrTm8GG2xQ"
        ></com.google.android.maps.MapView>     
         </LinearLayout>

И, наконец, код manifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.simplyDesign.BarCraw" android:versionCode="1"
    android:versionName="1.0">
    <uses-sdk android:minSdkVersion="4" />
    <uses-permission android:name="android.permission.INTERNET"></uses-permission>

    <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>
        <uses-library android:name="com.google.android.maps" />
    </application>
</manifest>

Ответы [ 2 ]

0 голосов
/ 04 июня 2011

определить идентификатор для MapView в xml

<com.google.android.maps.MapView
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent"
        android:enabled="true" 
        android:clickable="true"
        android:apiKey="0SN6PntBTxgMIeekPQm2Of1gnlDiHmrTm8GG2xQ"
         android:id="@+id/mapView"
        ></com.google.android.maps.MapView> 

и изменить эту строку ..

myMapView = (MapView) findViewById(R.layout.mapView);
0 голосов
/ 04 июня 2011

Вы должны дать вашему MapView android: id и передать его в findViewById (). В вашем коде вы ищете представление с идентификатором всего вашего макета. Это может только возвратить нуль ... и дать вам исключение NullPointerException при вызове getController () для нуля.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...