我有一个存储坐标的数据库,我希望这些读取并自动填充在地图上。我已经尝试了几次尝试,但似乎无法让它发挥作用。这是我的代码:
public class allmapactivity extends MapActivity {
MapController mControl;
GeoPoint GeoP;
MapView mapV;
private SQLiteAdapter mySQLiteAdapter;
Cursor cursor;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.map);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
mapV = (MapView) findViewById(R.id.mapview);
mapV.displayZoomControls(true);
mapV.setBuiltInZoomControls(true);
mapV.setSatellite(false);
List<Overlay> mapOverlays = mapV.getOverlays();
Drawable drawable = this.getResources().getDrawable(R.drawable.pin);
HelloItemizedOverlay itemizedoverlay = new HelloItemizedOverlay(drawable, this);
cursor = mySQLiteAdapter.queueAll5();
cursor.moveToFirst();
while (cursor.isAfterLast() == false) {
GeoPoint point = new GeoPoint((int) (cursor.getInt(cursor.getColumnIndex(SQLiteAdapter.KEY_CONTENT11))*1E6), (int) (cursor.getInt(cursor.getColumnIndex(SQLiteAdapter.KEY_CONTENT12))*1E6));
OverlayItem overlayitem = new OverlayItem(point, "Test", "Test");
itemizedoverlay.addOverlay(overlayitem);
mapOverlays.add(itemizedoverlay);
cursor.moveToNext();
}
}
@Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
}
如果任何人可以告诉我为什么这不起作用我将不胜感激! 附:这是logcat:
07-19 07:27:14.193: E/AndroidRuntime(531): FATAL EXCEPTION: main
07-19 07:27:14.193: E/AndroidRuntime(531): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.inh.mapbud/com.inh.mapbud.allmapactivity}: java.lang.NullPointerException
07-19 07:27:14.193: E/AndroidRuntime(531): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
07-19 07:27:14.193: E/AndroidRuntime(531): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
07-19 07:27:14.193: E/AndroidRuntime(531): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
07-19 07:27:14.193: E/AndroidRuntime(531): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
07-19 07:27:14.193: E/AndroidRuntime(531): at android.os.Handler.dispatchMessage(Handler.java:99)
07-19 07:27:14.193: E/AndroidRuntime(531): at android.os.Looper.loop(Looper.java:130)
07-19 07:27:14.193: E/AndroidRuntime(531): at android.app.ActivityThread.main(ActivityThread.java:3683)
07-19 07:27:14.193: E/AndroidRuntime(531): at java.lang.reflect.Method.invokeNative(Native Method)
07-19 07:27:14.193: E/AndroidRuntime(531): at java.lang.reflect.Method.invoke(Method.java:507)
07-19 07:27:14.193: E/AndroidRuntime(531): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
07-19 07:27:14.193: E/AndroidRuntime(531): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
07-19 07:27:14.193: E/AndroidRuntime(531): at dalvik.system.NativeStart.main(Native Method)
07-19 07:27:14.193: E/AndroidRuntime(531): Caused by: java.lang.NullPointerException
07-19 07:27:14.193: E/AndroidRuntime(531): at com.inh.mapbud.allmapactivity.onCreate(allmapactivity.java:45)
07-19 07:27:14.193: E/AndroidRuntime(531): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
07-19 07:27:14.193: E/AndroidRuntime(531): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
07-19 07:27:14.193: E/AndroidRuntime(531): ... 11 more
答案 0 :(得分:0)
检查allmapactivity活动的第45行。
答案 1 :(得分:0)
尝试移动此行
mapOverlays.add(itemizedoverlay);
在你的循环之外,似乎你正在为每个条目一次又一次地循环。