空指针到期是因为您没有使用 new 为变量 anand_nagar 创建 metro_nodes 实例
metro_nodes anand_nagar;
anand_nagar = new metro_nodes();//<----------------need this line to avoid NPE
anand_nagar.station = "anand_nagar";
并且还请遵循标准,例如类名应该像 java 中的 MetroNode .....
public class MainScreen extends MapActivity {
private MapController mController;
private double mLatitude,mLongitude;
private LocationManager mLoc;
private Location mLastknownloc;
private LocationListener mLoclistener;
private MapView mMapView;
private LinkedList<MetroNode> mStationLocations;
MetroNode mAnandNagar;
//in general we use cunstructor for initliaztion but in android we usesonCreate
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// ..other code ..............
List<GeoPoint> geoPoints = new ArrayList<GeoPoint>();
mStationLocations = new LinkedList<MetroNode>();
mAnandNagar = new MetroNode();
mAnandNagar.setStation("anand_nagar");
}
}
class MetroNode {
private String station;
private GeoPoint point;
public MetroNode(){
super();
}
public MetroNode(String station, GeoPoint point) {
super();
this.station = station;
this.point = point;
}
public String getStation() {
return station;
}
public void setStation(String station) {
this.station = station;
}
public GeoPoint getPoint() {
return point;
}
public void setPoint(GeoPoint point) {
this.point = point;
}
}