Questions tagged [arrayindexoutofboundsexception]

41 questions
354
votes
25 answers

What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it?

What does ArrayIndexOutOfBoundsException mean and how do I get rid of it? Here is a code sample that triggers the exception: String[] names = { "tom", "bob", "harry" }; for (int i = 0; i <= names.length; i++) { System.out.println(names[i]); }
Aaron
  • 11,239
  • 18
  • 58
  • 73
1
vote
4 answers

Codingbat challenge: zeroFront Stream API Solution

Given the task zeroFront notAlone from CodingBat: Return an array that contains the exact same numbers as the given array, but rearranged so that all the zeros are grouped at the start of the array. The order of the non-zero numbers does not…
1
vote
1 answer

Randomized QuickSort IndexOutOfBounds exception

this is the QuickSort Randomized that I've come up with, but it constantly throws out IndexOutOfBounds exception. Could I have some help with it? Thanks! import java.util.Random; public class QuickSort { void quickSort(int[] A, int start, int…
1
vote
0 answers

Caused by: java.lang.ArrayIndexOutOfBoundsException: length=0; index=0

I am trying to implement dark theme from fragment named as "Fragment_One" in android studio. This is from that fragment file if (!isChecked) { …
1
vote
1 answer

ArrayIndexOutOfBoundsException for Java Lambda

I am trying to convert my code to lambda version and I get java.lang.ArrayIndexOutOfBoundsException: 18 exception when I am building the code. This is the working code: private void run(){ Producer producer =…
Nu-ONE
  • 679
  • 5
  • 19
0
votes
1 answer

A confusing exception out of bound error in java while solving a spiral 2d matrix question

I was solving this question, trying to generate spiral matrix but repeatedly getting error only when the length of the matrix is odd. It is working fine when the length is even This is the code: public class spiral { public static void main(String[]…
0
votes
0 answers

I have having Array Index Out Of Bound Error in this code

HERE IS THE JAVA CODE.HAVING ARRAY INDEX OUT OF BOUND ERROR ON RUNTIME. i don't know what to do. I have tried every possible solution for this. This is the error i am getting "Exception in thread "AWT-EventQueue-0"…
0
votes
0 answers

BaseJdbcLogger queryStack multi thread not safe

i have opend sql debug log by adding: logging.level.com.***.mapper=debug then two thread in one request execute query separately by: Mono.zip(selectA(session),selectB(session)).flatMap(insertC(session)) occur exception like this…
0
votes
2 answers

ArrayIndexOutOfBoundsException in assistedViewModel after upgrading

@Keep @Composable @InternalCoroutinesApi @ExperimentalCoroutinesApi fun SetupNavigationHost( navController: NavHostController, ) { NavHost( navController = navController, startDestination = Screen.MainScreen.route, ) …
0
votes
0 answers

Using negative values as index in Arrays in JavaScript

why an error is not shown, when I try to add new elements in the array, using negative indexing. var myArray = new Array(3); myArray[0] = 0; myArray[1] = 1; myArray[2] = 2; myArray[-1] = -1; console.log(myArray); I was expecting an Error,But…
0
votes
0 answers

I have made a program in Java to accept and display a matrix but I am getting an ArrayIndexOutOfBoundsException

When I run the program, the accept method() runs smoothly but when I try to run the display() method, it shows an ArrayIndexOutOfBoundException: Index 0 out of bounds for length 0. I think it is because the values stored in matrix m are not passed…
rhucha
  • 1
0
votes
1 answer

Is it possible to get the value of an ArrayIndexOutOfBoundsException in Java?

I'm trying to do a program which uses a matrix and makes a new one with each element being the sum of every adjacent element of the original one plus itself. It's very easy to understand that the "edge" values of the matrix, if you access them by…
0
votes
2 answers

Unable to start activity: java.lang.ArrayIndexOutOfBoundsException

Everyone, hi! Friends, when you click on the button, a new activity does not start. The following exception occurs: java.lang.ArrayIndexOutOfBoundsException. The log of my error is presented below: E/AndroidRuntime: FATAL EXCEPTION: main …
0
votes
0 answers

Out of bounds exception on array that has not been initialized to a specific size

C# Coding for unity I have several arrays set as such. public float[] arrayName; no set number of elements anywhere in my code I can access the arrays up to 6 no problems but when I get to 7 I get an out of bounds exception. No where in my code…
Darren
  • 3
  • 4
0
votes
2 answers

I am receiving an error: no exception of type ArrayIndexOutOfBoundsException can be thrown; an exception type must be a subtype of class Throwable

import java.util.*; public class ArrayIndexOutOfBoundsException { public static void main(String[] args) { int[] array = new int[100]; //creating array with 100 storage spaces for(int i = 0; i < array.length; i++) { //for loop to…
1
2 3