2011-07-20 41 views
0
@Override 
protected void onCreate(Bundle arg0) { 
    super.onCreate(arg0); 
    setContentView(R.layout.map); 
    MapView mapView = (MapView) findViewById(R.id.mapview); 
    mapView.setBuiltInZoomControls(true); 
    badplatsName = getIntent().getStringExtra("se.brickit.badplatsen.badplatsname"); 
    lat = getIntent().getIntExtra("se.brickit.badplatsen.lat",0); 
    lon = getIntent().getIntExtra("se.brickit.badplatsen.lon",0); 

    List<Overlay> mapOverlays = mapView.getOverlays(); 
    Drawable drawable = this.getResources().getDrawable(R.drawable.smiley_flask); 
    BrMapViewItemOverlay itemizedoverlay = new BrMapViewItemOverlay(drawable); 
    GeoPoint point = new GeoPoint(lat,lon); 
    OverlayItem overlayitem = new OverlayItem(point, badplatsName, ""); 
    itemizedoverlay.addOverlay(overlayitem); 
    mapOverlays.add(itemizedoverlay); 
    mapView.getController().animateTo(point); 
    mapView.getController().zoomToSpan(6, 6); 
    mapView.setSatellite(true); 
} 

當我點擊重疊項時,應用程序崩潰。有誰知道原因?在mapview中點擊重疊項時發生崩潰

logcat有點奇怪,因爲它似乎試圖啓動一個活動,但我想要它做的是單擊時顯示一個名稱框。

07-20 14:36:56.303: ERROR/AndroidRuntime(15856): FATAL EXCEPTION: main 
07-20 14:36:56.303: ERROR/AndroidRuntime(15856): java.lang.NullPointerException 
07-20 14:36:56.303: ERROR/AndroidRuntime(15856):  at com.android.internal.app.AlertController$AlertParams.<init>(AlertController.java:743) 
07-20 14:36:56.303: ERROR/AndroidRuntime(15856):  at android.app.AlertDialog$Builder.<init>(AlertDialog.java:273) 
07-20 14:36:56.303: ERROR/AndroidRuntime(15856):  at se.brickit.badplatsen.BrMapViewItemOverlay.onTap(BrMapViewItemOverlay.java:43) 
07-20 14:36:56.303: ERROR/AndroidRuntime(15856):  at com.google.android.maps.ItemizedOverlay.onTap(ItemizedOverlay.java:453) 
07-20 14:36:56.303: ERROR/AndroidRuntime(15856):  at com.google.android.maps.OverlayBundle.onTap(OverlayBundle.java:83) 
07-20 14:36:56.303: ERROR/AndroidRuntime(15856):  at com.google.android.maps.MapView$1.onSingleTapUp(MapView.java:347) 
07-20 14:36:56.303: ERROR/AndroidRuntime(15856):  at com.google.android.maps.GestureDetector.onTouchEvent(GestureDetector.java:533) 
07-20 14:36:56.303: ERROR/AndroidRuntime(15856):  at com.google.android.maps.MapView.onTouchEvent(MapView.java:647) 
07-20 14:36:56.303: ERROR/AndroidRuntime(15856):  at android.view.View.dispatchTouchEvent(View.java:3765) 
07-20 14:36:56.303: ERROR/AndroidRuntime(15856):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:905) 
07-20 14:36:56.303: ERROR/AndroidRuntime(15856):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:944) 
07-20 14:36:56.303: ERROR/AndroidRuntime(15856):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:944) 
07-20 14:36:56.303: ERROR/AndroidRuntime(15856):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:944) 
07-20 14:36:56.303: ERROR/AndroidRuntime(15856):  at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1701) 
07-20 14:36:56.303: ERROR/AndroidRuntime(15856):  at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1116) 
07-20 14:36:56.303: ERROR/AndroidRuntime(15856):  at android.app.Activity.dispatchTouchEvent(Activity.java:2093) 
07-20 14:36:56.303: ERROR/AndroidRuntime(15856):  at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1685) 
07-20 14:36:56.303: ERROR/AndroidRuntime(15856):  at android.view.ViewRoot.handleMessage(ViewRoot.java:1802) 
07-20 14:36:56.303: ERROR/AndroidRuntime(15856):  at android.os.Handler.dispatchMessage(Handler.java:99) 
07-20 14:36:56.303: ERROR/AndroidRuntime(15856):  at android.os.Looper.loop(Looper.java:144) 
07-20 14:36:56.303: ERROR/AndroidRuntime(15856):  at android.app.ActivityThread.main(ActivityThread.java:4937) 
07-20 14:36:56.303: ERROR/AndroidRuntime(15856):  at java.lang.reflect.Method.invokeNative(Native Method) 
07-20 14:36:56.303: ERROR/AndroidRuntime(15856):  at java.lang.reflect.Method.invoke(Method.java:521) 
07-20 14:36:56.303: ERROR/AndroidRuntime(15856):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) 
07-20 14:36:56.303: ERROR/AndroidRuntime(15856):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) 
07-20 14:36:56.303: ERROR/AndroidRuntime(15856):  at dalvik.system.NativeStart.main(Native Method) 
07-20 14:36:58.163: ERROR/ActivityManager(96): fail to set top app changed! 
07-20 14:36:58.243: ERROR/AndroidRuntime(15896): FATAL EXCEPTION: main 
07-20 14:36:58.243: ERROR/AndroidRuntime(15896): java.lang.RuntimeException: Unable to start activity ComponentInfo{se.brickit.badplatsen/se.brickit.badplatsen.Tabs}: android.content.res.Resources$NotFoundException: Resource ID #0x0 
07-20 14:36:58.243: ERROR/AndroidRuntime(15896):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2787) 
07-20 14:36:58.243: ERROR/AndroidRuntime(15896):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2803) 
07-20 14:36:58.243: ERROR/AndroidRuntime(15896):  at android.app.ActivityThread.access$2300(ActivityThread.java:135) 
07-20 14:36:58.243: ERROR/AndroidRuntime(15896):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2136) 
07-20 14:36:58.243: ERROR/AndroidRuntime(15896):  at android.os.Handler.dispatchMessage(Handler.java:99) 
07-20 14:36:58.243: ERROR/AndroidRuntime(15896):  at android.os.Looper.loop(Looper.java:144) 
07-20 14:36:58.243: ERROR/AndroidRuntime(15896):  at android.app.ActivityThread.main(ActivityThread.java:4937) 
07-20 14:36:58.243: ERROR/AndroidRuntime(15896):  at java.lang.reflect.Method.invokeNative(Native Method) 
07-20 14:36:58.243: ERROR/AndroidRuntime(15896):  at java.lang.reflect.Method.invoke(Method.java:521) 
07-20 14:36:58.243: ERROR/AndroidRuntime(15896):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) 
07-20 14:36:58.243: ERROR/AndroidRuntime(15896):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) 
07-20 14:36:58.243: ERROR/AndroidRuntime(15896):  at dalvik.system.NativeStart.main(Native Method) 
07-20 14:36:58.243: ERROR/AndroidRuntime(15896): Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x0 
07-20 14:36:58.243: ERROR/AndroidRuntime(15896):  at android.content.res.Resources.getValue(Resources.java:892) 
07-20 14:36:58.243: ERROR/AndroidRuntime(15896):  at android.content.res.Resources.getDrawable(Resources.java:580) 
07-20 14:36:58.243: ERROR/AndroidRuntime(15896):  at se.brickit.badplatsen.Tabs.onCreate(Tabs.java:192) 
07-20 14:36:58.243: ERROR/AndroidRuntime(15896):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1069) 
07-20 14:36:58.243: ERROR/AndroidRuntime(15896):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2751) 
07-20 14:36:58.243: ERROR/AndroidRuntime(15896):  ... 11 more 
07-20 14:37:00.053: ERROR/ClockWidget(209): weatherClock onReceive~ mUseAnimation:false 
07-20 14:37:00.053: ERROR/ClockWidget(209): weatherClock onReceive~ mUseAnimation:false 

詩篇這裏是覆蓋類:

public class BrMapViewItemOverlay extends ItemizedOverlay { 
private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>(); 
private Context mContext; 

public BrMapViewItemOverlay(Drawable defaultMarker) { 
    super(boundCenterBottom(defaultMarker)); 
} 

public BrMapViewItemOverlay(Drawable defaultMarker, Context context) { 
    super(defaultMarker); 
    mContext = context; 
} 

public void addOverlay(OverlayItem overlay) { 
    mOverlays.add(overlay); 
    populate(); 
} 

@Override 
protected OverlayItem createItem(int i) { 
    return mOverlays.get(i); 
} 

@Override 
public int size() { 
    return mOverlays.size(); 
} 

@Override 
protected boolean onTap(int index) { 
    OverlayItem item = mOverlays.get(index); 
    AlertDialog.Builder dialog = new AlertDialog.Builder(mContext); 
    dialog.setTitle(item.getTitle()); 
    dialog.setMessage(item.getSnippet()); 
    dialog.show(); 
    return true; 
} 

}

+0

你在onTap或MapView onTouchListener方法中做了什麼? –

回答

1

替換該行

BrMapViewItemOverlay itemizedoverlay = new BrMapViewItemOverlay(drawable);

BrMapViewItemOverlay itemizedoverlay = new BrMapViewItemOverlay(drawable, this); 

您還沒有傳遞的上下文,因此充氣AlertDialog導致失敗。

0

從logcat的輸出,我可以說是你Tabs.java行號問題文件,在同一行中,我相信你正在嘗試引用像字符串,顏色,drawables或任何資源,但它給了ResourceNotFoundException僅僅是因爲它沒有得到該資源的ID實際上是urce。

僅供試用,請執行project -> clean以便它再次構建項目。它只是我的猜測,因爲我也做了很多次。

總之,只需檢查Tabs.java文件中的行號192。