我试图修改HelloGoogleMaps教程,因此我可以使用for循环填充列表,而不是单独输入。采取婴儿步骤,我尝试只添加一个点,但当我调用GeoPoint列表的添加方法时,我得到一个空指针异常。感谢。
import java.util.List;
import com.google.android.maps.GeoPoint;
//import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.OverlayItem;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
public class HelloGoogleMaps extends MapActivity {
/** Called when the activity is first created. */
public List<GeoPoint> geoPoints;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//allows zooming
MapView mapView = (MapView) findViewById(R.id.mapview);
mapView.setBuiltInZoomControls(true);
List<Overlay> mapOverlays = mapView.getOverlays();
Drawable drawable = this.getResources().getDrawable(R.drawable.icon);
HelloItemizedOverlay itemizedoverlay = new HelloItemizedOverlay(drawable);
//create adding points
GeoPoint point1 = new GeoPoint(19240000,-99120000);
geoPoints.add(point1);//<<<<<<-------this is where i get the exception
//eventual for loop goes here
}
@Override
protected boolean isRouteDisplayed() {
return false;
}
}//end Map Activity
答案 0 :(得分:1)
您需要初始化列表:
private List<GeoPoint> geoPoints = new ArrayList<GeoPoint>();
// And also make it private...