-2

So, i'm using an array in my program, and it gives me this error:

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException

The error is in fourth line of this code:

int n = numbers.length, numBigger10 = 0; 
for (int i = 0; i < n; i++)
            if (numbers[i] > 10)
                numbersBigger10[i] = numbers[i];               
                numBigger10++;               

What can I do to solve?

If you want to know more details about the error please feel free to ask.

1 Answers1

0

The reason you are getting this NullPointerException is because in your if statement you are trying to assign numbers[i] to an index location that is not present in the numbersBigger10 array.

i.e. The two arrays, numbers and numbersBigger10 have different sizes.

edit - It would be helpful to see more code though, specifically the part where you declared numbersBigger10.

Bergis
  • 85
  • 7