问题描述
我试图从AsyncTask的更新用户界面的图形页面。多次试验之后,我不断收到此异常错误。我已经把try / catch语句大部分的地方,但我仍然得到错误。
这里是logcat的错误:
05-20 16:19:22.273:E / AndroidRuntime(26776):java.lang.IndexOutOfBoundsException:无效的索引2,大小为0
05-20 16:19:22.273:E / AndroidRuntime(26776):在java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:255)
05-20 16:19:22.273:E / AndroidRuntime(26776):在java.util.ArrayList.get(ArrayList.java:308)
05-20 16:19:22.273:E / AndroidRuntime(26776):在org.osmdroid.views.overlay.ItemizedOverlay.getItem(ItemizedOverlay.java:158)
05-20 16:19:22.273:E / AndroidRuntime(26776):在org.osmdroid.views.overlay.ItemizedOverlay.drawSafe(ItemizedOverlay.java:125)
05-20 16:19:22.273:E / AndroidRuntime(26776):在org.osmdroid.views.overlay.SafeDrawOverlay.draw(SafeDrawOverlay.java:85)
05-20 16:19:22.273:E / AndroidRuntime(26776):在org.osmdroid.views.overlay.OverlayManager.onDraw(OverlayManager.java:141)
05-20 16:19:22.273:E / AndroidRuntime(26776):在org.osmdroid.views.MapView.dispatchDraw(MapView.java:1024)
05-20 16:19:22.273:E / AndroidRuntime(26776):在android.view.View.getDisplayList(View.java:13357)
05-20 16:19:22.273:E / AndroidRuntime(26776):在android.view.View.getDisplayList(View.java:13404)
05-20 16:19:22.273:E / AndroidRuntime(26776):在android.view.View.draw(View.java:14182)
05-20 16:19:22.273:E / AndroidRuntime(26776):在android.view.ViewGroup.drawChild(ViewGroup.java:3103)
05-20 16:19:22.273:E / AndroidRuntime(26776):在android.view.ViewGroup.dispatchDraw(ViewGroup.java:2940)
05-20 16:19:22.273:E / AndroidRuntime(26776):在android.view.View.getDisplayList(View.java:13357)
05-20 16:19:22.273:E / AndroidRuntime(26776):在android.view.View.getDisplayList(View.java:13404)
05-20 16:19:22.273:E / AndroidRuntime(26776):在android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3077)
05-20 16:19:22.273:E / AndroidRuntime(26776):在android.view.View.getDisplayList(View.java:13300)
05-20 16:19:22.273:E / AndroidRuntime(26776):在android.view.View.getDisplayList(View.java:13404)
05-20 16:19:22.273:E / AndroidRuntime(26776):在android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3077)
05-20 16:19:22.273:E / AndroidRuntime(26776):在android.view.View.getDisplayList(View.java:13300)
05-20 16:19:22.273:E / AndroidRuntime(26776):在android.view.View.getDisplayList(View.java:13404)
05-20 16:19:22.273:E / AndroidRuntime(26776):在android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3077)
05-20 16:19:22.273:E / AndroidRuntime(26776):在android.view.View.getDisplayList(View.java:13300)
05-20 16:19:22.273:E / AndroidRuntime(26776):在android.view.View.getDisplayList(View.java:13404)
05-20 16:19:22.273:E / AndroidRuntime(26776):在android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3077)
05-20 16:19:22.273:E / AndroidRuntime(26776):在android.view.View.getDisplayList(View.java:13300)
05-20 16:19:22.273:E / AndroidRuntime(26776):在android.view.View.getDisplayList(View.java:13404)
05-20 16:19:22.273:E / AndroidRuntime(26776):在android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3077)
05-20 16:19:22.273:E / AndroidRuntime(26776):在android.view.View.getDisplayList(View.java:13300)
05-20 16:19:22.273:E / AndroidRuntime(26776):在android.view.View.getDisplayList(View.java:13404)
05-20 16:19:22.273:E / AndroidRuntime(26776):在android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3077)
05-20 16:19:22.273:E / AndroidRuntime(26776):在android.view.View.getDisplayList(View.java:13300)
05-20 16:19:22.273:E / AndroidRuntime(26776):在android.view.View.getDisplayList(View.java:13404)
05-20 16:19:22.273:E / AndroidRuntime(26776):在android.view.HardwareRenderer $ GlRenderer.buildDisplayList(HardwareRenderer.java:1570)
05-20 16:19:22.273:E / AndroidRuntime(26776):在android.view.HardwareRenderer $ GlRenderer.draw(HardwareRenderer.java:1449)
05-20 16:19:22.273:E / AndroidRuntime(26776):在android.view.ViewRootImpl.draw(ViewRootImpl.java:2381)
05-20 16:19:22.273:E / AndroidRuntime(26776):在android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2253)
05-20 16:19:22.273:E / AndroidRuntime(26776):在android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1883)
05-20 16:19:22.273:E / AndroidRuntime(26776):在android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1000)
05-20 16:19:22.273:E / AndroidRuntime(26776):在android.view.ViewRootImpl $ TraversalRunnable.run(ViewRootImpl.java:5670)
05-20 16:19:22.273:E / AndroidRuntime(26776):在android.view.Choreographer $ CallbackRecord.run(Choreographer.java:761)
05-20 16:19:22.273:E / AndroidRuntime(26776):在android.view.Choreographer.doCallbacks(Choreographer.java:574)
05-20 16:19:22.273:E / AndroidRuntime(26776):在android.view.Choreographer.doFrame(Choreographer.java:544)
05-20 16:19:22.273:E / AndroidRuntime(26776):在android.view.Choreographer $ FrameDisplayEventReceiver.run(Choreographer.java:747)
05-20 16:19:22.273:E / AndroidRuntime(26776):在android.os.Handler.handleCallback(Handler.java:733)
05-20 16:19:22.273:E / AndroidRuntime(26776):在android.os.Handler.dispatchMessage(Handler.java:95)
05-20 16:19:22.273:E / AndroidRuntime(26776):在android.os.Looper.loop(Looper.java:136)
05-20 16:19:22.273:E / AndroidRuntime(26776):在android.app.ActivityThread.main(ActivityThread.java:5017)
有关我可以读出的日志,您试图访问不具有的长度还没有一个数组。在创建数组或acessing它之前,你需要给它一定的长度initalize它。在Java中,它看起来是这样的:
INT [] arrayExcample;
arrayExcample =新INT [10];
这阵共包含10个免费的空间为整数值了。如果你想要一个其他类型的数据,仅仅是更换两节INT。
如果你想缩短code你也可以使用以下,根据上下文,来实现你的阵列:
INT [] = arrayExcample新INT [10];
I'm trying to update UI from AsyncTask for MapView. After many trials, I keep getting this exception error. I've put try/catch most of the places, yet still I get the error.
Here is Logcat error:
05-20 16:19:22.273: E/AndroidRuntime(26776): java.lang.IndexOutOfBoundsException: Invalid index 2, size is 0
05-20 16:19:22.273: E/AndroidRuntime(26776): at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:255)
05-20 16:19:22.273: E/AndroidRuntime(26776): at java.util.ArrayList.get(ArrayList.java:308)
05-20 16:19:22.273: E/AndroidRuntime(26776): at org.osmdroid.views.overlay.ItemizedOverlay.getItem(ItemizedOverlay.java:158)
05-20 16:19:22.273: E/AndroidRuntime(26776): at org.osmdroid.views.overlay.ItemizedOverlay.drawSafe(ItemizedOverlay.java:125)
05-20 16:19:22.273: E/AndroidRuntime(26776): at org.osmdroid.views.overlay.SafeDrawOverlay.draw(SafeDrawOverlay.java:85)
05-20 16:19:22.273: E/AndroidRuntime(26776): at org.osmdroid.views.overlay.OverlayManager.onDraw(OverlayManager.java:141)
05-20 16:19:22.273: E/AndroidRuntime(26776): at org.osmdroid.views.MapView.dispatchDraw(MapView.java:1024)
05-20 16:19:22.273: E/AndroidRuntime(26776): at android.view.View.getDisplayList(View.java:13357)
05-20 16:19:22.273: E/AndroidRuntime(26776): at android.view.View.getDisplayList(View.java:13404)
05-20 16:19:22.273: E/AndroidRuntime(26776): at android.view.View.draw(View.java:14182)
05-20 16:19:22.273: E/AndroidRuntime(26776): at android.view.ViewGroup.drawChild(ViewGroup.java:3103)
05-20 16:19:22.273: E/AndroidRuntime(26776): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2940)
05-20 16:19:22.273: E/AndroidRuntime(26776): at android.view.View.getDisplayList(View.java:13357)
05-20 16:19:22.273: E/AndroidRuntime(26776): at android.view.View.getDisplayList(View.java:13404)
05-20 16:19:22.273: E/AndroidRuntime(26776): at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3077)
05-20 16:19:22.273: E/AndroidRuntime(26776): at android.view.View.getDisplayList(View.java:13300)
05-20 16:19:22.273: E/AndroidRuntime(26776): at android.view.View.getDisplayList(View.java:13404)
05-20 16:19:22.273: E/AndroidRuntime(26776): at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3077)
05-20 16:19:22.273: E/AndroidRuntime(26776): at android.view.View.getDisplayList(View.java:13300)
05-20 16:19:22.273: E/AndroidRuntime(26776): at android.view.View.getDisplayList(View.java:13404)
05-20 16:19:22.273: E/AndroidRuntime(26776): at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3077)
05-20 16:19:22.273: E/AndroidRuntime(26776): at android.view.View.getDisplayList(View.java:13300)
05-20 16:19:22.273: E/AndroidRuntime(26776): at android.view.View.getDisplayList(View.java:13404)
05-20 16:19:22.273: E/AndroidRuntime(26776): at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3077)
05-20 16:19:22.273: E/AndroidRuntime(26776): at android.view.View.getDisplayList(View.java:13300)
05-20 16:19:22.273: E/AndroidRuntime(26776): at android.view.View.getDisplayList(View.java:13404)
05-20 16:19:22.273: E/AndroidRuntime(26776): at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3077)
05-20 16:19:22.273: E/AndroidRuntime(26776): at android.view.View.getDisplayList(View.java:13300)
05-20 16:19:22.273: E/AndroidRuntime(26776): at android.view.View.getDisplayList(View.java:13404)
05-20 16:19:22.273: E/AndroidRuntime(26776): at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3077)
05-20 16:19:22.273: E/AndroidRuntime(26776): at android.view.View.getDisplayList(View.java:13300)
05-20 16:19:22.273: E/AndroidRuntime(26776): at android.view.View.getDisplayList(View.java:13404)
05-20 16:19:22.273: E/AndroidRuntime(26776): at android.view.HardwareRenderer$GlRenderer.buildDisplayList(HardwareRenderer.java:1570)
05-20 16:19:22.273: E/AndroidRuntime(26776): at android.view.HardwareRenderer$GlRenderer.draw(HardwareRenderer.java:1449)
05-20 16:19:22.273: E/AndroidRuntime(26776): at android.view.ViewRootImpl.draw(ViewRootImpl.java:2381)
05-20 16:19:22.273: E/AndroidRuntime(26776): at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2253)
05-20 16:19:22.273: E/AndroidRuntime(26776): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1883)
05-20 16:19:22.273: E/AndroidRuntime(26776): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1000)
05-20 16:19:22.273: E/AndroidRuntime(26776): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5670)
05-20 16:19:22.273: E/AndroidRuntime(26776): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761)
05-20 16:19:22.273: E/AndroidRuntime(26776): at android.view.Choreographer.doCallbacks(Choreographer.java:574)
05-20 16:19:22.273: E/AndroidRuntime(26776): at android.view.Choreographer.doFrame(Choreographer.java:544)
05-20 16:19:22.273: E/AndroidRuntime(26776): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747)
05-20 16:19:22.273: E/AndroidRuntime(26776): at android.os.Handler.handleCallback(Handler.java:733)
05-20 16:19:22.273: E/AndroidRuntime(26776): at android.os.Handler.dispatchMessage(Handler.java:95)
05-20 16:19:22.273: E/AndroidRuntime(26776): at android.os.Looper.loop(Looper.java:136)
05-20 16:19:22.273: E/AndroidRuntime(26776): at android.app.ActivityThread.main(ActivityThread.java:5017)
For what I can read out of the log, you are trying to access an array that does not have a length yet. When creating the array or before acessing it you need to initalize it by giving it a certain length. In Java, it looks something like this:
int [] arrayExcample;
arrayExcample = new int [10];
This array contains a total of 10 free "spaces" for Integer values now. If you want an other type of data, just replace the two "int" by it.
If you want to shorten your code you could also use the following, depending on the context, to implement your Array:
int [] arrayExcample = new int [10];
这篇关于排列出OSMdroid,边界异常从AsyncTask的更新过程中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!