开发者

Android Google Map Api Error

I have a question about transferring data through Intent() to a MapView.

String coorx = temptItem.getCordx();
String coory = temptItem.getCordy();
goTomap.putExtra("x", coorx);
goTomap.putExtra("y", coory);
System.out.println(coorx);
startActivity(goTomap);

where goTomap is my Intent: goTomap = new Intent(this,MyMap.class); But after I click on the ListView to go to another class, it gives:

java.lang.RuntimeException: Unable to start activity .....
java.lang.NullPointerException

My manifest is from many sample codes around the web.

<activity android:name=".MyMap" 
            android:label="location">
           <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
        </activity>

Anyway to solve this?

EDIT Added MyMap

package com.nyp.stud084839L.isbconnects;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;

import android.os.Bundle;

public class MyMap extends MapActivity{
    private MapView mapView;
    private MapController mc;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        su开发者_如何学运维per.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        mapView = (MapView) findViewById(R.id.map_view);
        String coordinates[] = {"40.747778", "-73.985556"};
        double lat = Double.parseDouble(coordinates[0]);
        double lng = Double.parseDouble(coordinates[1]);

        GeoPoint p = new GeoPoint(
            (int) (lat * 1E6), 
            (int) (lng * 1E6));

        mc = mapView.getController();
        mc.animateTo(p);
        mc.setZoom(17); 
        mapView.invalidate();        
    }

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

}


From what you've said in comments, your local variable mapView must be null (i.e. findViewById() is failing) and therefore the problem is that your layout/main.xml does not contain a MapView with the attribute android:id="@+id/map_view".

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜