我已经在我的应用程序中添加了OSMDroID地图,它工作正常,但是如果我缩小地图,它会崩溃.
我在将地图加载到用户当前位置时添加了一个项目,并在加载地图后在AsyncTask中加载了另外10个项目.
更新:工作解决方案
在下面的旧代码中,我在用户位置的地图上添加了一个“基本”项,并为地图创建了ItemizedItemOverlay.然后,我加载了更多OverlayItems并将其添加到列表中,但是它们没有出现在地图上.
现在,我在AsyncTask完成所有项目的加载之后创建ItemizedItemOverlay,现在所有项目都可见,OnItemSingleTapUp可以按预期工作,在地图上双击也可以正常工作,并且不再崩溃.我仍然不太清楚是什么原因导致了崩溃,但是它的工作原理是这样的.
可能的问题:
OverlayItems列表用零个对象初始化(显然),但是我添加了一个OverlayItem之后,它包含1个OverlayItem,又包含11个null对象(或null-Refernces?null-Items?正确的术语是什么?)
编辑:没有引起问题,仍然很奇怪.
编辑:看来我只会在添加更多项目时崩溃.
这是我的完整代码和Logcat:
mResourceProxy = new DefaultResourceProxyImpl(getApplicationContext());mapVIEw.setTileSource(TileSourceFactory.MAPNIK);mapVIEw.setBuiltInZoomControls(true);mapVIEw.setMultitouchControls(true);mapController = this.mapVIEw.getController();mapController.setZoom(25);GeoPoint center = new GeoPoint(DataManager.glat, DataManager.glon);mapController.setCenter(center);mLocMgr = (LocationManager) getSystemService(LOCATION_SERVICE);mLocMgr.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 100, this);items = new ArrayList<OverlayItem>(); // items Now nullitems.add(new OverlayItem("Here", "SampleDescription", center));// items Now contains 1 OverlayItem and 11 null-itemsthis.mLocationOverlay = new ItemizedIconOverlay<OverlayItem>(items,new ItemizedIconOverlay.OnItemGestureListener<OverlayItem>() { @OverrIDe public boolean onItemSingleTapUp(final int index, final OverlayItem item) { Intent intent=new Intent(); intent.putExtra("newShopname", item.mTitle); intent.putExtra("newShopAdd", item.mDescription); setResult(RESulT_OK, intent); finish(); return true; } @OverrIDe public boolean onItemLongPress(final int index, final OverlayItem item) { toast = Toast.makeText(ShopChooseActivity.this, item.mTitle + ", " + item.mDescription, Toast.LENGTH_LONG); toast.show(); return false; } }, mResourceProxy);this.mapVIEw.getoverlays().add(this.mLocationOverlay);mapVIEw.invalIDate();
在这里,我称之为AsyncTask:
loadMap = new LoadChooseShop(ShopChooseActivity.this, items).execute();
在这里,我“刷新”了地图:
@OverrIDe public voID onTaskCompleted(int returncode) { try { items = loadMap.get(); if(items != null) mapVIEw.invalIDate(); else { Toast.makeText(getApplicationContext(), R.string.error_connectionfailure , Toast.LENGTH_LONG).show(); setResult(RESulT_CANCELED); finish(); } } catch (InterruptedException e) { } catch (ExecutionException e) { } }
和XML:
<org.osmdroID.vIEws.MapVIEw xmlns:androID="http://schemas.androID.com/apk/res/androID" androID:ID="@+ID/mapvIEw" androID:layout_wIDth="fill_parent" androID:layout_height="fill_parent"/>
大编辑:我的大多数问题现在已解决,但仍然崩溃.
当我双击地图时,它总是崩溃,但不仅如此.
如果我将clickable = true添加到XML,它不再崩溃,但是我无法移动地图.
Logcat:
07-15 14:41:16.339: E/inputEventReceiver(17302): Exception dispatching input event.07-15 14:41:16.339: E/MessageQueue-JNI(17302): Exception in MessageQueue callback: handleReceiveCallback07-15 14:41:16.404: E/MessageQueue-JNI(17302): java.lang.indexoutofboundsexception: InvalID index 1, size is 107-15 14:41:16.404: E/MessageQueue-JNI(17302): at java.util.ArrayList.throwindexoutofboundsexception(ArrayList.java:251)07-15 14:41:16.404: E/MessageQueue-JNI(17302): at java.util.ArrayList.get(ArrayList.java:304)07-15 14:41:16.404: E/MessageQueue-JNI(17302): at org.osmdroID.vIEws.overlay.itemizedoverlay.getItem(itemizedoverlay.java:157)07-15 14:41:16.404: E/MessageQueue-JNI(17302): at org.osmdroID.vIEws.overlay.ItemizedIconOverlay.activateSelectedItems(ItemizedIconOverlay.java:170)07-15 14:41:16.404: E/MessageQueue-JNI(17302): at org.osmdroID.vIEws.overlay.ItemizedIconOverlay.onSingleTapUp(ItemizedIconOverlay.java:117)07-15 14:41:16.404: E/MessageQueue-JNI(17302): at org.osmdroID.vIEws.overlay.OverlayManager.onSingleTapUp(OverlayManager.java:291)07-15 14:41:16.404: E/MessageQueue-JNI(17302): at org.osmdroID.vIEws.MapVIEw$MapVIEwGestureDetectorListener.onSingleTapUp(MapVIEw.java:1539)07-15 14:41:16.404: E/MessageQueue-JNI(17302): at androID.vIEw.GestureDetector.ontouchEvent(GestureDetector.java:1344)07-15 14:41:16.404: E/MessageQueue-JNI(17302): at org.osmdroID.vIEws.MapVIEw.dispatchtouchEvent(MapVIEw.java:904)07-15 14:41:16.404: E/MessageQueue-JNI(17302): at androID.vIEw.VIEwGroup.dispatchtransformedtouchEvent(VIEwGroup.java:2416)07-15 14:41:16.404: E/MessageQueue-JNI(17302): at androID.vIEw.VIEwGroup.dispatchtouchEvent(VIEwGroup.java:2159)07-15 14:41:16.404: E/MessageQueue-JNI(17302): at androID.vIEw.VIEwGroup.dispatchtransformedtouchEvent(VIEwGroup.java:2416)07-15 14:41:16.404: E/MessageQueue-JNI(17302): at androID.vIEw.VIEwGroup.dispatchtouchEvent(VIEwGroup.java:2159)07-15 14:41:16.404: E/MessageQueue-JNI(17302): at androID.vIEw.VIEwGroup.dispatchtransformedtouchEvent(VIEwGroup.java:2416)07-15 14:41:16.404: E/MessageQueue-JNI(17302): at androID.vIEw.VIEwGroup.dispatchtouchEvent(VIEwGroup.java:2159)07-15 14:41:16.404: E/MessageQueue-JNI(17302): at androID.vIEw.VIEwGroup.dispatchtransformedtouchEvent(VIEwGroup.java:2416)07-15 14:41:16.404: E/MessageQueue-JNI(17302): at androID.vIEw.VIEwGroup.dispatchtouchEvent(VIEwGroup.java:2159)07-15 14:41:16.404: E/MessageQueue-JNI(17302): at androID.vIEw.VIEwGroup.dispatchtransformedtouchEvent(VIEwGroup.java:2416)07-15 14:41:16.404: E/MessageQueue-JNI(17302): at androID.vIEw.VIEwGroup.dispatchtouchEvent(VIEwGroup.java:2159)07-15 14:41:16.404: E/MessageQueue-JNI(17302): at androID.vIEw.VIEwGroup.dispatchtransformedtouchEvent(VIEwGroup.java:2416)07-15 14:41:16.404: E/MessageQueue-JNI(17302): at androID.vIEw.VIEwGroup.dispatchtouchEvent(VIEwGroup.java:2159)07-15 14:41:16.404: E/MessageQueue-JNI(17302): at com.androID.internal.policy.impl.PhoneWindow$DecorVIEw.superdispatchtouchEvent(PhoneWindow.java:2115)07-15 14:41:16.404: E/MessageQueue-JNI(17302): at com.androID.internal.policy.impl.PhoneWindow.superdispatchtouchEvent(PhoneWindow.java:1468)07-15 14:41:16.404: E/MessageQueue-JNI(17302): at androID.app.Activity.dispatchtouchEvent(Activity.java:2487)07-15 14:41:16.404: E/MessageQueue-JNI(17302): at com.androID.internal.policy.impl.PhoneWindow$DecorVIEw.dispatchtouchEvent(PhoneWindow.java:2063)07-15 14:41:16.404: E/MessageQueue-JNI(17302): at androID.vIEw.VIEw.dispatchPointerEvent(VIEw.java:7520)07-15 14:41:16.404: E/MessageQueue-JNI(17302): at androID.vIEw.VIEwRootImpl.deliverPointerEvent(VIEwRootImpl.java:3376)07-15 14:41:16.404: E/MessageQueue-JNI(17302): at androID.vIEw.VIEwRootImpl.deliverinputEvent(VIEwRootImpl.java:3308)07-15 14:41:16.404: E/MessageQueue-JNI(17302): at androID.vIEw.VIEwRootImpl.doProcessinputEvents(VIEwRootImpl.java:4402)07-15 14:41:16.404: E/MessageQueue-JNI(17302): at androID.vIEw.VIEwRootImpl.enqueueinputEvent(VIEwRootImpl.java:4380)07-15 14:41:16.404: E/MessageQueue-JNI(17302): at androID.vIEw.VIEwRootImpl$WindowinputEventReceiver.oninputEvent(VIEwRootImpl.java:4484)07-15 14:41:16.404: E/MessageQueue-JNI(17302): at androID.vIEw.inputEventReceiver.dispatchinputEvent(inputEventReceiver.java:171)07-15 14:41:16.404: E/MessageQueue-JNI(17302): at androID.os.MessageQueue.nativePollOnce(Native Method)07-15 14:41:16.404: E/MessageQueue-JNI(17302): at androID.os.MessageQueue.next(MessageQueue.java:125)07-15 14:41:16.404: E/MessageQueue-JNI(17302): at androID.os.Looper.loop(Looper.java:124)07-15 14:41:16.404: E/MessageQueue-JNI(17302): at androID.app.ActivityThread.main(ActivityThread.java:4898)07-15 14:41:16.404: E/MessageQueue-JNI(17302): at java.lang.reflect.Method.invokeNative(Native Method)07-15 14:41:16.404: E/MessageQueue-JNI(17302): at java.lang.reflect.Method.invoke(Method.java:511)07-15 14:41:16.404: E/MessageQueue-JNI(17302): at com.androID.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)07-15 14:41:16.404: E/MessageQueue-JNI(17302): at com.androID.internal.os.ZygoteInit.main(ZygoteInit.java:773)07-15 14:41:16.404: E/MessageQueue-JNI(17302): at dalvik.system.NativeStart.main(Native Method)07-15 14:41:21.914: D/AndroIDRuntime(17302): Shutting down VM07-15 14:41:21.914: W/dalvikvm(17302): threadID=1: thread exiting with uncaught exception (group=0x417cc2a0)07-15 14:41:21.984: E/AndroIDRuntime(17302): FATAL EXCEPTION: main07-15 14:41:21.984: E/AndroIDRuntime(17302): java.lang.indexoutofboundsexception: InvalID index 1, size is 107-15 14:41:21.984: E/AndroIDRuntime(17302): at java.util.ArrayList.throwindexoutofboundsexception(ArrayList.java:251)07-15 14:41:21.984: E/AndroIDRuntime(17302): at java.util.ArrayList.get(ArrayList.java:304)07-15 14:41:21.984: E/AndroIDRuntime(17302): at org.osmdroID.vIEws.overlay.itemizedoverlay.getItem(itemizedoverlay.java:157)07-15 14:41:21.984: E/AndroIDRuntime(17302): at org.osmdroID.vIEws.overlay.ItemizedIconOverlay.activateSelectedItems(ItemizedIconOverlay.java:170)07-15 14:41:21.984: E/AndroIDRuntime(17302): at org.osmdroID.vIEws.overlay.ItemizedIconOverlay.onSingleTapUp(ItemizedIconOverlay.java:117)07-15 14:41:21.984: E/AndroIDRuntime(17302): at org.osmdroID.vIEws.overlay.OverlayManager.onSingleTapUp(OverlayManager.java:291)07-15 14:41:21.984: E/AndroIDRuntime(17302): at org.osmdroID.vIEws.MapVIEw$MapVIEwGestureDetectorListener.onSingleTapUp(MapVIEw.java:1539)07-15 14:41:21.984: E/AndroIDRuntime(17302): at androID.vIEw.GestureDetector.ontouchEvent(GestureDetector.java:1344)07-15 14:41:21.984: E/AndroIDRuntime(17302): at org.osmdroID.vIEws.MapVIEw.dispatchtouchEvent(MapVIEw.java:904)07-15 14:41:21.984: E/AndroIDRuntime(17302): at androID.vIEw.VIEwGroup.dispatchtransformedtouchEvent(VIEwGroup.java:2416)07-15 14:41:21.984: E/AndroIDRuntime(17302): at androID.vIEw.VIEwGroup.dispatchtouchEvent(VIEwGroup.java:2159)07-15 14:41:21.984: E/AndroIDRuntime(17302): at androID.vIEw.VIEwGroup.dispatchtransformedtouchEvent(VIEwGroup.java:2416)07-15 14:41:21.984: E/AndroIDRuntime(17302): at androID.vIEw.VIEwGroup.dispatchtouchEvent(VIEwGroup.java:2159)07-15 14:41:21.984: E/AndroIDRuntime(17302): at androID.vIEw.VIEwGroup.dispatchtransformedtouchEvent(VIEwGroup.java:2416)07-15 14:41:21.984: E/AndroIDRuntime(17302): at androID.vIEw.VIEwGroup.dispatchtouchEvent(VIEwGroup.java:2159)07-15 14:41:21.984: E/AndroIDRuntime(17302): at androID.vIEw.VIEwGroup.dispatchtransformedtouchEvent(VIEwGroup.java:2416)07-15 14:41:21.984: E/AndroIDRuntime(17302): at androID.vIEw.VIEwGroup.dispatchtouchEvent(VIEwGroup.java:2159)07-15 14:41:21.984: E/AndroIDRuntime(17302): at androID.vIEw.VIEwGroup.dispatchtransformedtouchEvent(VIEwGroup.java:2416)07-15 14:41:21.984: E/AndroIDRuntime(17302): at androID.vIEw.VIEwGroup.dispatchtouchEvent(VIEwGroup.java:2159)07-15 14:41:21.984: E/AndroIDRuntime(17302): at androID.vIEw.VIEwGroup.dispatchtransformedtouchEvent(VIEwGroup.java:2416)07-15 14:41:21.984: E/AndroIDRuntime(17302): at androID.vIEw.VIEwGroup.dispatchtouchEvent(VIEwGroup.java:2159)07-15 14:41:21.984: E/AndroIDRuntime(17302): at com.androID.internal.policy.impl.PhoneWindow$DecorVIEw.superdispatchtouchEvent(PhoneWindow.java:2115)07-15 14:41:21.984: E/AndroIDRuntime(17302): at com.androID.internal.policy.impl.PhoneWindow.superdispatchtouchEvent(PhoneWindow.java:1468)07-15 14:41:21.984: E/AndroIDRuntime(17302): at androID.app.Activity.dispatchtouchEvent(Activity.java:2487)07-15 14:41:21.984: E/AndroIDRuntime(17302): at com.androID.internal.policy.impl.PhoneWindow$DecorVIEw.dispatchtouchEvent(PhoneWindow.java:2063)07-15 14:41:21.984: E/AndroIDRuntime(17302): at androID.vIEw.VIEw.dispatchPointerEvent(VIEw.java:7520)07-15 14:41:21.984: E/AndroIDRuntime(17302): at androID.vIEw.VIEwRootImpl.deliverPointerEvent(VIEwRootImpl.java:3376)07-15 14:41:21.984: E/AndroIDRuntime(17302): at androID.vIEw.VIEwRootImpl.deliverinputEvent(VIEwRootImpl.java:3308)07-15 14:41:21.984: E/AndroIDRuntime(17302): at androID.vIEw.VIEwRootImpl.doProcessinputEvents(VIEwRootImpl.java:4402)07-15 14:41:21.984: E/AndroIDRuntime(17302): at androID.vIEw.VIEwRootImpl.enqueueinputEvent(VIEwRootImpl.java:4380)07-15 14:41:21.984: E/AndroIDRuntime(17302): at androID.vIEw.VIEwRootImpl$WindowinputEventReceiver.oninputEvent(VIEwRootImpl.java:4484)07-15 14:41:21.984: E/AndroIDRuntime(17302): at androID.vIEw.inputEventReceiver.dispatchinputEvent(inputEventReceiver.java:171)07-15 14:41:21.984: E/AndroIDRuntime(17302): at androID.os.MessageQueue.nativePollOnce(Native Method)07-15 14:41:21.984: E/AndroIDRuntime(17302): at androID.os.MessageQueue.next(MessageQueue.java:125)07-15 14:41:21.984: E/AndroIDRuntime(17302): at androID.os.Looper.loop(Looper.java:124)07-15 14:41:21.984: E/AndroIDRuntime(17302): at androID.app.ActivityThread.main(ActivityThread.java:4898)07-15 14:41:21.984: E/AndroIDRuntime(17302): at java.lang.reflect.Method.invokeNative(Native Method)07-15 14:41:21.984: E/AndroIDRuntime(17302): at java.lang.reflect.Method.invoke(Method.java:511)07-15 14:41:21.984: E/AndroIDRuntime(17302): at com.androID.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)07-15 14:41:21.984: E/AndroIDRuntime(17302): at com.androID.internal.os.ZygoteInit.main(ZygoteInit.java:773)07-15 14:41:21.984: E/AndroIDRuntime(17302): at dalvik.system.NativeStart.main(Native Method)
更新:
如果我不添加更多项目(不调用AsyncTask),则点击该项目即可正常工作并提供预期的结果-但是,如果我添加更多项目,则在Tap上崩溃. (在同一项目的Tap上,其他的甚至都不可见)
解决方法:
在上一次编辑中,您发布了完整的stacktrace-谢谢,这就是我们所需要的.我会忽略“下载瓷砖时出错”,因为那不是崩溃您的应用程序的原因.崩溃发生在“ indexoutofboundsexception”中.您的问题开始因过多的信息而变得一发不可收拾-我们将其简化并找出问题所在.当崩溃发生时您在做什么-您在问题中说双击时会发生崩溃,但该异常与ItemizedIconOverlay和onSingleTapUp有关.可以尝试的一些事情:
>如果不使用ItemizedIconOverlay,是否会崩溃?
>如果您不向ItemizedIconOverlay添加任何项目,是否会崩溃?
>查看ItemizedItemOverlay,如果将onSingleTapUp()中的所有代码移至onSingleTapConfirmed()会怎样.那才是真正的归属.如果您不想从源代码重建osmdroID,那么您应该能够扩展ItemizedIconOverlay并覆盖这两种方法-在onSingleTapUp()中返回false并将该方法中的所有旧代码放入onSingleTapConfirmed中.我刚刚添加了一张Issue 450的门票.
>您说双击以放大时会崩溃,当您点击一个项目时会怎么样?那会崩溃吗?确保放大时没有添加新项目.
因此,itemizedoverlay通过调用size()进行工作,然后为每个项目调用getMarker(index).由于某种原因,您的itemizedoverlay认为只有2个项目时才有2个项目.也许您设置了一些断点,尤其是在addItem()或addItems()和size()中.也许,与上述答案一起,将提供一些线索!
总结以上是内存溢出为你收集整理的缩小时OSMDroid崩溃全部内容,希望文章能够帮你解决缩小时OSMDroid崩溃所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)