2012-07-19 46 views
0

我有一個數據庫的座標存儲,我想這些閱讀並自動填充在地圖上。我嘗試了幾次嘗試,但似乎無法得到這個工作。這裏是我的代碼:從座標存儲在SQLite中創建地點 - 安卓

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

} 

如果任何人可以告訴我爲什麼這不起作用,我將不勝感激! P.S.這裏是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

哪一個是行號45 – 2012-07-19 08:12:40

回答

0

檢查allmapactivity活動的第45行。

+0

有沒有一種方法可以啓用行號? – user1526003 2012-07-19 16:51:49

0

嘗試移動此行

mapOverlays.add(itemizedoverlay); 

你的循環之外,它似乎要爲每個條目一次又一次的循環。