Android Projects

Android Development Books


ArrayIndexOutOfBoundsException in java or android

How to occurs ArrayIndexOutOfBoundsException error in android during compling or runing your program . So let me suppose some problems and their some tricky answers, which is more helpful for solving your problem.

Main reason to occurs this is. Thrown when the an array is indexed with a value less than zero, or greater than or equal to the size of the array.

The ArrayTrouble example illustrates an error which will occur if an attempt is made to access the elements of an array of zero length:
import java.lang.reflect.Array;
import static java.lang.System.out;

public class ArrayTrouble {
    public static void main(String... args) {
        Object o = Array.newInstance(int.class, 0);
        int[] i = (int[])o;
        int[] j = new int[0];
        out.format("i.length = %d, j.length = %d, args.length = %d%n",
                   i.length, j.length, args.length);
        Array.getInt(o, 0);  // ArrayIndexOutOfBoundsException
$ java ArrayTrouble
i.length = 0, j.length = 0, args.length = 0
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException
        at java.lang.reflect.Array.getInt(Native Method)
        at ArrayTrouble.main(

Tip: It is possible to have arrays with no elements (empty arrays). There are only a few cases in common code where they are seen but they can occur in reflection inadvertently. Of course, it is not possible to set/get the values of an empty array because an ArrayIndexOutOfBoundsException will be thrown.

Please visit this site which has more information about this.

Now other problems are:
1.ArrayIndexOutOfBoundsException occurs when you connect database

2.horizontal slide on ListView throw ArrayIndexOutOfBoundsException

3. ArrayIndexOutOfBoundsException with custom Android Adapter for multiple views in ListView

4.  The exception is thrown from getY() from onTouchEvent()

5.ArrayIndexOutOfBoundsException in ItemizedOverlay

6.ItemizedOverlay + ArrayIndexOutOfBoundsException / NullPointerException workarounds

7.Computing the distance between two consecutive location updates and callculating the time

8. Using indexOfChromosomes : 48 indexOfGens : 20 double Truncation; double Crossover; double Mutation; int Generation;

9.Exception in thread “main” java.lang.ArrayIndexOutOfBoundsException to solve Exception in thread “main” java.lang.ArithmeticException: / by zero?

More details click here: google
Share this post
  • Share to Facebook
  • Share to Twitter
  • Share to Google+
  • Share to Stumble Upon
  • Share to Evernote
  • Share to Blogger
  • Share to Email
  • Share to Yahoo Messenger
  • More...


Thanks for your comment

:) :-) :)) =)) :( :-( :(( :d :-d @-) :p :o :>) (o) [-( :-? (p) :-s (m) 8-) :-t :-b b-( :-# =p~ :-$ (b) (f) x-) (k) (h) (c) cheer

Related Posts Plugin for WordPress, Blogger...
© Google Android Lovers
Designed by BlogThietKe Cooperated with Duy Pham
Released under Creative Commons 3.0 CC BY-NC 3.0