OSMDroid缩小时崩溃OSMDroid

2023-09-07 23:39:04 作者:我去你妈

从来就增加了一个OSMDroid地图在我的应用程序,它工作正常,但如果我缩小,它崩溃。

I´ve added a OSMDroid map in my app and it works fine, but if I zoom out, it crashes.

我在AsyncTask的加载映射之后添加一个项目在装入图在user's当前位置,和负载10更

I add one Item while loading the Map at the user´s current position, and load 10 more in an AsyncTask after loading the map.

更新:工作液

在我的老code以下,我增加了一个基地-Item到地图的user's位置,并创建了一个 ItemizedItemOverlay 的地图。然后我装更多的OverlayItems,并将它们添加到列表中,但他们didn't出现在地图上。

In my old Code below, I added one "base"-Item to the map at the user´s location and created an ItemizedItemOverlay for the map. Then I loaded more OverlayItems and added them to the list, but they didn´t appear on the map.

现在我创建 ItemizedItemOverlay 之后的AsyncTask完成加载的所有项目,现在项目都是可见的, OnItemSingleTapUp 正在为在地图上意,双击工程,以及有没有更多的崩溃。我还是鸵鸟政策真的知道是什么引起的崩溃,但它的工作原理是这样的。

Now I create the ItemizedItemOverlay after the AsyncTask has finished loading all the Items, now the Items are all visible, OnItemSingleTapUp is working as intended, Double-Tap on the map works as well and there are no more crashes. I still don´t really know what caused the crashes, but it works like this.

可能的问题: OverlayItems列表是零对象(显然)初始化,但以后我加一OverlayItem,它包含1 OverlayItem + 11多个空对象(或空Refernces?空项目?what's正确的称呼?) 编辑: didnt导致的问题,仍然陌生

Possible problem: The List of OverlayItems is initialized with zero objects (obviously), but after I add one OverlayItem, it contains 1 OverlayItem + 11 more null-Objects (or null-Refernces? null-Items? what´s the correct term?) didnt cause the problems, still strange.

编辑:它似乎我只是增加更多的物品时,得到一个崩溃

It seems as I only get a crash when adding more Items.

Here's我完全code和logcat的:

Here´s my full code and 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 null
items.add(new OverlayItem("Here", "SampleDescription", center));
// items now contains 1 OverlayItem and 11 null-items

this.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的:

Here I call the AsyncTask:

loadMap = new LoadChooseShop(ShopChooseActivity.this, items).execute();

在这里,我刷新图:

And here I "refresh" the map:

@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"/>

BIG编辑:我的大部分问题都已经解决,它仍然崩溃

BIG Most of my problems are now resolved, it still crashes.

它总是在地图上崩溃时,我双击,但不是唯一的话。 如果我添加点击= TRUE 到XML,它不崩溃了,但我不能移动地图。

It always crashes when I double-tap on the map, but not only then. If I add clickable=true to XML, it doesnt crash anymore, but I can´t move the map.

在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: handleReceiveCallback
07-15 14:41:16.404: E/MessageQueue-JNI(17302): java.lang.IndexOutOfBoundsException: Invalid index 1, size is 1
07-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 VM
07-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: main
07-15 14:41:21.984: E/AndroidRuntime(17302): java.lang.IndexOutOfBoundsException: Invalid index 1, size is 1
07-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的),轻击项目工程,并提供预期的结果 - 但如果我添加更多的项目,它崩溃自来水。 (在同一个项目的点击,其他aren't偶可见)

Update: If I don´t add more Items (don´t call AsyncTask), tapping on the Item works and delivers the expected result - but if I add more Items, it crashes on Tap. (on Tap of the same Item, the others aren´t even visible)

推荐答案

在上次编辑您发布的完整的堆栈跟踪 - 谢谢你,这就是我们所需要的。我会忽略错误下载瓦,因为这不是崩溃您的应用程序。这次事故是发生在IndexOutOfBoundsException异常。你的问题已经开始失控了太多的信息 - 让我们简化下来,找出问题。你在做什么的时候崩溃发生 - 你在你的问题说,它发生在你双击,但例外是关系到ItemizedIconOverlay和onSingleTapUp。有些事情尝试:

In your last edit you posted the full stacktrace - thank you, that is what we need. I would ignore the "Error downloading tile" since that isn't what is crashing your app. The crash is happening in the "IndexOutOfBoundsException". Your question is starting to spiral out of control with too much information - let's simplify it down and isolate the problem. What are you doing when the crash happens - you say in your question that it happens when you double-tap but the exception is related to the ItemizedIconOverlay and the onSingleTapUp. Some things to try:

它会崩溃,如果你不使用ItemizedIconOverlay? 是否崩溃,如果你不添加任何产品的ItemizedIconOverlay。 纵观ItemizedItemOverlay,如果你在onSingleTapUp感动了所有的code()来onSingleTapConfirmed()。这真的是它所属。如果你不想重新构建从源头osmdroid,那么你应该能够扩展ItemizedIconOverlay并覆盖这两种方法 - 以 onSingleTapUp返回false()并把所有的旧的$从方法 onSingleTapConfirmed C $℃。我只是增加了一个票的问题450 。 您说的崩溃,当你双击放大,那么当你只需轻按一个项目?它会崩溃呢?确保当你放大你是不是增加新的项目。 Does it crash if you don't use the ItemizedIconOverlay? Does it crash if you don't add any items to the ItemizedIconOverlay. Looking at the ItemizedItemOverlay, what if you moved all the code in onSingleTapUp() to onSingleTapConfirmed(). That is really where it belongs. If you don't want to rebuild osmdroid from source, then you should be able to extend ItemizedIconOverlay and override both methods - return false in onSingleTapUp() and put all the old code from that method in onSingleTapConfirmed. I just added a ticket for that Issue 450. You say it crashes when you double-tap to zoom in, what about when you just tap on an item? Does it crash then? Make sure you aren't adding new items when you zoom in.

于是ItemizedOverlay作品通过调用尺寸()键,然后调用 getMarker(指数)为每个项目。出于某种原因,你ItemizedOverlay认为它有2项时,它只有一个。也许,如果你设置一些断点,特别是在的addItem()为addItems()尺寸()。也许这,连同答案上面,会提供一些​​线索!

So the ItemizedOverlay works by calling size() and then it calls getMarker(index) for each item. For some reason your ItemizedOverlay thinks it has 2 items when it only has one. Maybe if you set some breakpoints, particularly in addItem() or addItems() and size(). Maybe that, along with the answers to the above, will provide some clues!