1

i am having listview in my view pager and i have used TitlePageIndicator. Everything seems to be working fine but randomly it crashes due IndexOutOfBound exception. I am not sure what is the cause for it. Below i have attached the stacktrace of it. Also i found this link and its mentioned that this has been fixed in 2.1.0. But i am using the 2.3.1 version.

`

> 07-31 15:32:10.242: W/System.err(6720): java.lang.IndexOutOfBoundsException: Invalid index 4, size is 1
07-31 15:32:10.247: W/System.err(6720):     at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:251)
07-31 15:32:10.247: W/System.err(6720):     at java.util.ArrayList.get(ArrayList.java:304)
07-31 15:32:10.247: W/System.err(6720):     at android.widget.HeaderViewListAdapter.getView(HeaderViewListAdapter.java:225)
07-31 15:32:10.247: W/System.err(6720):     at android.widget.AbsListView.obtainView(AbsListView.java:2452)
07-31 15:32:10.247: W/System.err(6720):     at android.widget.ListView.makeAndAddView(ListView.java:1775)
07-31 15:32:10.247: W/System.err(6720):     at android.widget.ListView.fillDown(ListView.java:678)
07-31 15:32:10.247: W/System.err(6720):     at android.widget.ListView.fillSpecific(ListView.java:1336)
07-31 15:32:10.247: W/System.err(6720):     at android.widget.ListView.layoutChildren(ListView.java:1606)
07-31 15:32:10.247: W/System.err(6720):     at android.widget.AbsListView.onLayout(AbsListView.java:2303)
07-31 15:32:10.247: W/System.err(6720):     at android.view.View.layout(View.java:14063)
07-31 15:32:10.247: W/System.err(6720):     at android.view.ViewGroup.layout(ViewGroup.java:4655)
07-31 15:32:10.247: W/System.err(6720):     at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1655)
07-31 15:32:10.247: W/System.err(6720):     at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1513)
07-31 15:32:10.247: W/System.err(6720):     at android.widget.LinearLayout.onLayout(LinearLayout.java:1426)
07-31 15:32:10.247: W/System.err(6720):     at android.view.View.layout(View.java:14063)
07-31 15:32:10.247: W/System.err(6720):     at android.view.ViewGroup.layout(ViewGroup.java:4655)
07-31 15:32:10.247: W/System.err(6720):     at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
07-31 15:32:10.247: W/System.err(6720):     at android.view.View.layout(View.java:14063)
07-31 15:32:10.247: W/System.err(6720):     at android.view.ViewGroup.layout(ViewGroup.java:4655)
07-31 15:32:10.247: W/System.err(6720):     at android.support.v4.view.ViewPager.onLayout(ViewPager.java:1520)
07-31 15:32:10.247: W/System.err(6720):     at android.view.View.layout(View.java:14063)
07-31 15:32:10.247: W/System.err(6720):     at android.view.ViewGroup.layout(ViewGroup.java:4655)
07-31 15:32:10.247: W/System.err(6720):     at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1655)
07-31 15:32:10.252: W/System.err(6720):     at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1513)
07-31 15:32:10.252: W/System.err(6720):     at android.widget.LinearLayout.onLayout(LinearLayout.java:1426)
07-31 15:32:10.252: W/System.err(6720):     at android.view.View.layout(View.java:14063)
07-31 15:32:10.252: W/System.err(6720):     at android.view.ViewGroup.layout(ViewGroup.java:4655)
07-31 15:32:10.252: W/System.err(6720):     at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
07-31 15:32:10.252: W/System.err(6720):     at android.view.View.layout(View.java:14063)
07-31 15:32:10.252: W/System.err(6720):     at android.view.ViewGroup.layout(ViewGroup.java:4655)
07-31 15:32:10.252: W/System.err(6720):     at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1655)
07-31 15:32:10.252: W/System.err(6720):     at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1513)
07-31 15:32:10.257: W/System.err(6720):     at android.widget.LinearLayout.onLayout(LinearLayout.java:1426)
07-31 15:32:10.257: W/System.err(6720):     at android.view.View.layout(View.java:14063)
07-31 15:32:10.257: W/System.err(6720):     at android.view.ViewGroup.layout(ViewGroup.java:4655)
07-31 15:32:10.257: W/System.err(6720):     at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
07-31 15:32:10.257: W/System.err(6720):     at android.view.View.layout(View.java:14063)
07-31 15:32:10.257: W/System.err(6720):     at android.view.ViewGroup.layout(ViewGroup.java:4655)
07-31 15:32:10.257: W/System.err(6720):     at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2017)
07-31 15:32:10.257: W/System.err(6720):     at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1838)
07-31 15:32:10.257: W/System.err(6720):     at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1131)
07-31 15:32:10.257: W/System.err(6720):     at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4611)
07-31 15:32:10.257: W/System.err(6720):     at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725)
07-31 15:32:10.257: W/System.err(6720):     at android.view.Choreographer.doCallbacks(Choreographer.java:555)
07-31 15:32:10.257: W/System.err(6720):     at android.view.Choreographer.doFrame(Choreographer.java:525)
07-31 15:32:10.257: W/System.err(6720):     at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711)
07-31 15:32:10.257: W/System.err(6720):     at android.os.Handler.handleCallback(Handler.java:615)
07-31 15:32:10.257: W/System.err(6720):     at android.os.Handler.dispatchMessage(Handler.java:92)
07-31 15:32:10.257: W/System.err(6720):     at android.os.Looper.loop(Looper.java:137)
07-31 15:32:10.257: W/System.err(6720):     at android.app.ActivityThread.main(ActivityThread.java:4898)
07-31 15:32:10.257: W/System.err(6720):     at java.lang.reflect.Method.invokeNative(Native Method)
07-31 15:32:10.257: W/System.err(6720):     at java.lang.reflect.Method.invoke(Method.java:511)
07-31 15:32:10.257: W/System.err(6720):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1008)
07-31 15:32:10.257: W/System.err(6720):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:775)
07-31 15:32:10.257: W/System.err(6720):     at dalvik.system.NativeStart.main(Native Method)

`
4

2 回答 2

3

It's a little hard to pinpoint your exact problem without seeing some code, but let me attempt an educated guess.

Is there a chance that you're accessing your adapter by manually calling getAdapter() on your ListView?

If so, instead of calling getAdapter(), when you're initially setting the adapter, keep a reference to it in a new class variable. Then, when you need it, access it using your new variable.

于 2013-08-06T02:57:25.997 回答
0

I've just solved my problem which is similar with yours. In my case it's because I clear my arraylist right before my asynctask runs. So what Im saying is when I scroll my List View, my array list is empty, to let the adapter knows the arraylist is changed and empty I have to notify it first.


arraylistTimeline.clear(); adapterTimeline.notifyDataSetChanged(); <--- wasnt here when error occure like you mentioned

TimelineRestoURL tURL = new TimelineRestoURL(); tURL.execute();


Just like that. Hope it helps.

于 2013-08-26T03:14:20.550 回答