【发布时间】:2012-01-08 04:09:45
【问题描述】:
我正在尝试修改 HelloGoogleMaps 教程,以便我可以使用 for 循环而不是单独键入它们来填充列表。采取婴儿步骤,我尝试只添加一个点,但是当我调用 GeoPoint 列表的 add 方法时出现空指针异常。谢谢。
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
【问题讨论】:
标签: android exception pointers null