1

我有一个存储坐标的数据库,我想读取这些坐标并在地图上自动填充。我已经尝试了几次,但似乎无法让它发挥作用。这是我的代码:

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;
}

}

如果有人能告诉我为什么这不起作用,我将不胜感激!PS这里是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
4

2 回答 2

0

检查 allmapactivity 活动的第 45 行。

于 2012-07-19T07:38:05.277 回答
0

尝试移动这条线

mapOverlays.add(itemizedoverlay);

在您的循环之外,您似乎在为每个条目一次又一次地循环。

于 2013-12-30T09:32:05.360 回答