不要告诉我location.setLatitude(latitude);location.setLongitude(longitude);不好使 代码如下Intent descriptionTodestination = getIntent();
getlatitude = descriptionTodestination.getDoubleExtra("latitude", getlatitude);
getlongitude = descriptionTodestination.getDoubleExtra("longitude", getlongitude);
System.out.println(""+getlatitude+" "+getlongitude);

//destination.setLatitude(getlatitude);
//destination.setLongitude(getlongitude);注释的这两句不好使 会抛出空指针异常 不知道怎么回事呢?!?!

解决方案 »

  1.   

    碰到空指针你最好看一下 destination 这个值有没有new 了??
      

  2.   

    double getlatitude,getlongitude;
    private LocationManager locationmanager;
    String bestProvider;
    private MapController mapcontroller;
    private GeoPoint geopoint;
    MyPositionOverlay positionOverlay;
    Location destination; public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.destination);

    MapView destination_mapView = (MapView) findViewById(R.id.destination_mapView);
    mapcontroller = destination_mapView.getController();

    //得到传递过来的经纬度
    Intent descriptionTodestination = getIntent();
    getlatitude = descriptionTodestination.getDoubleExtra("latitude", getlatitude);
    getlongitude = descriptionTodestination.getDoubleExtra("longitude", getlongitude);
    System.out.println(""+getlatitude+" "+getlongitude);

    destination.setLatitude(getlatitude);
    destination.setLongitude(getlongitude);
    destination = new Location(destination);
      

  3.   

    先new destination 然后在setLatitude也是一样的空指针
      

  4.   

    你再试试吧:
    Location destination = new Location(LocationManager.GPS_PROVIDER);多半是这个问题,没有new就直接用了,肯定是空的。
      

  5.   


    才发现:destination = new Location(destination);你这句代码错了。不知道你从那学来的!!!!
    改成这样吧:
    destination = new Location(LocationManager.GPS_PROVIDER);
    destination.setLatitude(getlatitude);
    destination.setLongitude(getlongitude);