android - ArrayIndexOutOfBoundsException on displaying data from arraylist -


I am using a piece of code to display the image and text on the footer of my app. The image and text should change after every 30 seconds. The code works fine, but it randomly gives an exception and my app suddenly crashes after a few minutes. Please help me on this, if I work for the same work, then I will be grateful.

Exception:

  07-24 17:14: 32.812: E / AndroidRuntime (4196): java.lang.ArrayIndexOutOfBoundsException: length = 2; Index = 2 07-24 17: 14: 32.812: E / Android Random (4196): at java.util.ArrayList.get (ArrayList.java:306) 07-24 17: 14: 32.812: E / Androidrentaim (41 9 6): 14: 32.812: e / AndroidRuntime (4196): on android.os.Handler.handleCallback (Handler.java:615 com.ht.mpnews.FragmentTabActivity $ Task $ 1.run (FragmentTabActivity.java: 491) on 07-24 17) 07-24 17: 14: 32.812: E / Android Random (4196): Android.OS. Hendlr Dispatch Message (Handlrkjawaः 92) 07-24 17: 14: 32.812: E / Androidrentaim (41 9 6): Android on .os.Looper.loop (Looper.java:137) 07-24 17: 14: 32.812 e / Androidrentaim (41 9 6): Android.ap.aktivtitredkmain (Gtividhitredkxava 0745) 07-24 17:14: 32.812: e / AndroidRuntime (4196): java.lang.reflect.Method.invokeNative (original Resident Method) 07-24 in 17: 14: 32.812: E / AndroidRuntime (4196): at java.lang.reflect.Method.invoke (Method.javaread11) 07-24 17:14: 32.812: E / AndroidRuntime ( 4196): com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run (ZygoteInit.java:786) 07-24 17:14 at 32.812: e / Android Rentaim (41 9 6): on com.android.interna l .os.ZygoteInit.main (Z   

code: P>

  private handler mHandler = new handler (); Int i = 0; Class Task Operations Runnabel {@Override Public Zero Run () {Log D. ("ARRRE list size ::", AdsDisplay.arrListAds.size () + ""); For (i = 0; i & lt; AdsDisplay.arrListAds.size (); i ++) {System.out.println ("Loop ::::::::::" + i) for; MHandler.post (New Runnable) {@Override Public Zero Run (println ("runnable ::::::::" + i) for the loop; imageLoader.displayImage (AdsDisplay.arrListAds.get (i) .ad_imageUrl, ivAdd); println (AdsDisplay.arrListAds.get (i) .ad_detail); tvAddContent.setText ( "::" + AdsDisplay.arrListAds.get (i) .ad_detail); tvAddContent. SetOnClickListener (new OnClickListener) {@ Override on public void (see ARG0) {log d. ( "links clicked :::", AdsDisplay.arrListAds.get (i) .ad_link); Braujhrintent intent = new intent (Intent.ACTION_VIEW, Uri.parse (AdsDisplay.arrListAds.get (i) .ad_link); startActivity (browserIntent);}}); If (i == (AdsDisplay.arrListAds.size ()) - 1) {i = -1; System.out.println ("Loop inside :::::::" + i);}}}); Try {Thread.sleep (30000); } Grip (Interrupted e) e.printStackTrace (); }}}}}    

Try changing if (i == ( AdsDisplay ArrListAds.size ()) - 1) to if (i == (AdsDisplay.arrListAds.size ()))

Comments

Popular posts from this blog

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

Matlab transpose a table vector -

c# - Textbox not clickable but editable -