• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how to solve arrayindexoutofbound exception

 
Ranch Hand
Posts: 214
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
iam getting this exception at logcat can anyone please help me solve it....i tried hard but could resolve

iam tryingg to get a listview of image and text view toghtr where i get this exception
the first time i load the listview i dont face any problem,later when i go back and load again it gives exception
 
Ranch Hand
Posts: 95
Python C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please post the code.
Maybe I can help you!!!
 
Saloon Keeper
Posts: 7582
176
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
By not accessing array indices that are higher than allowed for the array in question. If an array has n elements, then n-1 is the highest array index you can use.
 
Naishadh Parmar
Ranch Hand
Posts: 95
Python C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, I was going to see those problems when she would post the code
 
Tim Moores
Saloon Keeper
Posts: 7582
176
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
More important than anyone pointing right at the problem is the understanding of what this exception means, and how one can guard against it in the future (and how to debug it if one isn't sure why it happens).
 
Suzzane Pinto
Ranch Hand
Posts: 214
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator



this is where i get arrayindexoutofbound exception
 
Tim Moores
Saloon Keeper
Posts: 7582
176
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So: where do you think the problem happens? You didn't post the top of the stack trace, which is where the most important information is - namely, in which line of code.

The only array seems to be SongsActivity1.myArr, so that's likely where the problem is. And the code is accessing it with an index that is too large. What do you think has happened? *How* could it have happened?
 
Suzzane Pinto
Ranch Hand
Posts: 214
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
here is my code...which gives a listview with imageview and text


i get the proper output when first time the list is created....later when i add an item then it gives arrayindexoutofbound exception...
can anyone suggest...i have pasted the adapter for the listview where actually m stuck....
please suggest help
 
Suzzane Pinto
Ranch Hand
Posts: 214
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
can someone please get me a solution....searching solution since so many days....this arrayindex exception will make me mad n my application will crash....

looking for help...
 
Suzzane Pinto
Ranch Hand
Posts: 214
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
the listview displays as many time as i want without any problem but wen i add a new element to the arraylist and then go to load the listview it gives me arrayindexoutofbound exception.....found no solution anywhere
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did you read what Tim said?
 
Tim Moores
Saloon Keeper
Posts: 7582
176
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In which line of code does the exception happen? What is the value of the index that causes the problem? What is the length of the array? These are all runtime issues that you need to work out, just looking at code isn't going to help much.
 
Suzzane Pinto
Ranch Hand
Posts: 214
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
the problem is in line 53,56..length of the array depends upon the values to arraylist added at runtime..
 
Suzzane Pinto
Ranch Hand
Posts: 214
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
the problem is here if(s.equals(values[position])) get the exception here
 
Suzzane Pinto
Ranch Hand
Posts: 214
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
03-06 13:30:08.772: W/System.err(571): java.lang.ArrayIndexOutOfBoundsException
03-06 13:30:08.772: W/System.err(571): at com.ixifoto.albums.NewMobileAdapter.getView(NewMobileAdapter.java:94)
03-06 13:30:08.772: W/System.err(571): at android.widget.AbsListView.obtainView(AbsListView.java:1430)
03-06 13:30:08.772: W/System.err(571): at android.widget.ListView.makeAndAddView(ListView.java:1745)
03-06 13:30:08.781: W/System.err(571): at android.widget.ListView.fillDown(ListView.java:670)
03-06 13:30:08.781: W/System.err(571): at android.widget.ListView.fillFromTop(ListView.java:727)
03-06 13:30:08.790: W/System.err(571): at android.widget.ListView.layoutChildren(ListView.java:1598)
03-06 13:30:08.790: W/System.err(571): at android.widget.AbsListView.onLayout(AbsListView.java:1260)
03-06 13:30:08.790: W/System.err(571): at android.view.View.layout(View.java:7175)
03-06 13:30:08.790: W/System.err(571): at android.widget.RelativeLayout.onLayout(RelativeLayout.java:912)
03-06 13:30:08.790: W/System.err(571): at android.view.View.layout(View.java:7175)
03-06 13:30:08.790: W/System.err(571): at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
03-06 13:30:08.790: W/System.err(571): at android.view.View.layout(View.java:7175)
03-06 13:30:08.790: W/System.err(571): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1254)
03-06 13:30:08.790: W/System.err(571): at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1130)
03-06 13:30:08.790: W/System.err(571): at android.widget.LinearLayout.onLayout(LinearLayout.java:1047)
03-06 13:30:08.790: W/System.err(571): at android.view.View.layout(View.java:7175)
03-06 13:30:08.790: W/System.err(571): at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
03-06 13:30:08.790: W/System.err(571): at android.view.View.layout(View.java:7175)
03-06 13:30:08.790: W/System.err(571): at android.view.ViewRoot.performTraversals(ViewRoot.java:1140)
03-06 13:30:08.790: W/System.err(571): at android.view.ViewRoot.handleMessage(ViewRoot.java:1859)
03-06 13:30:08.790: W/System.err(571): at android.os.Handler.dispatchMessage(Handler.java:99)
03-06 13:30:08.790: W/System.err(571): at android.os.Looper.loop(Looper.java:123)
03-06 13:30:08.800: W/System.err(571): at android.app.ActivityThread.main(ActivityThread.java:3683)
03-06 13:30:08.800: W/System.err(571): at java.lang.reflect.Method.invokeNative(Native Method)
03-06 13:30:08.800: W/System.err(571): at java.lang.reflect.Method.invoke(Method.java:507)
03-06 13:30:08.800: W/System.err(571): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
03-06 13:30:08.800: W/System.err(571): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
03-06 13:30:08.800: W/System.err(571): at dalvik.system.NativeStart.main(Native Method)
 
Suzzane Pinto
Ranch Hand
Posts: 214
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
my adapter class is
 
Tim Moores
Saloon Keeper
Posts: 7582
176
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Moores wrote:What is the value of the index that causes the problem? What is the length of the array? These are all runtime issues that you need to work out, just looking at code isn't going to help much.

 
Suzzane Pinto
Ranch Hand
Posts: 214
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
the problem is here if(s.equals(values[position])) get the exception here

the items are added at runtime
 
Tim Moores
Saloon Keeper
Posts: 7582
176
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you really not understand why we can't do anything without the information I'm asking for? Actually, once you have that information, you are in a position to address the problem yourself.
 
Suzzane Pinto
Ranch Hand
Posts: 214
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
its says invalid index 6,size is 0
 
Tim Moores
Saloon Keeper
Posts: 7582
176
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So?

The problem is still the same I mentioned in my very first post:

By not accessing array indices that are higher than allowed for the array in question.

 
Suzzane Pinto
Ranch Hand
Posts: 214
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
iam not geting arrayindexoutofbound exception now...but when i add element is not getting displayed in the listview....the size of string is same as size of images array here..it should display the image for the string value...but here it is displaying the image i select over other string value
please suggest...any idea
 
Tim Moores
Saloon Keeper
Posts: 7582
176
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You should start a new topic for unrelated questions, lest it gets confusing.
 
Suzzane Pinto
Ranch Hand
Posts: 214
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
sory for the wrong post
 
Tim Moores
Saloon Keeper
Posts: 7582
176
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Moores wrote:You should start a new topic for unrelated questions, lest it gets confusing.


Be sure to include detailed information about what you perceive to be the problem.
reply
    Bookmark Topic Watch Topic
  • New Topic