FAQ Database Discussion Community


ArrayIndexOutOfBounds Exception Java

java,indexoutofboundsexception
I can't seem to figure out what's wrong or why it gives me the output it does, I'll copy& paste my code for the two classes and the console output I get and maybe someone better than me at Java can help figure this out, I'm certain it's something trivial:...

Array out of bound exception while splitting the String

java,string,split,indexoutofboundsexception
While splitting the String using ',' I am getting Array out of bound exception. Please find below the program. public static void main(String[] args) { String c="1,10k ABC D, XYZ AB,,,,,,12345,,,,,,,,,,,,,,,,,,,,,,,,,,,,,"; System.out.println(c.split(",")[11]); } Even the 11th element is null i want to print the null string (Because in some records...

VBA string array with unknown amount of strings

arrays,string,vba,indexoutofboundsexception
First of all let me all congratulate you on a superb forum! it's helped me Loads! so far with getting my little program working... and now I'm finally stuck. I am attempting to automate Outlook to send tailored Offers to clients through a UserForm. We offer 5 types of solutions...

how to get the row item position number in listview adapter class

android,listview,indexoutofboundsexception
I have followed other questions and have done what they have mentioned but didn't get the result. my getTag() gives me ArrayIndexOutofBound error. Adapter Class private final Home context; private LayoutInflater inflater; private int position; private ListView mListView; private ArrayList<Task> tasks; public ListViewAdapter(Home context,ArrayList<Task> tasks) { super(); this.context=context; inflater =...

How to print a statement using ArrayOutOfBoundException

java,oop,exception,indexoutofboundsexception
I am trying to print a System.out.println statement using ArrayOutOfBoundException but I am not quite sure how to go about doing this. Here is what I have done so far: public class Ex4 { public static void main(String[] args) { String text= ""; if ( args.length <= 3 ) {...

How to to keep this merge array method in-bounds?

java,arrays,indexing,merge,indexoutofboundsexception
I have to write a method that combines two arrays that are already in ascending order into one array sorted in ascending order. However, they are different lengths and so incrementing brings them out of bounds. Visualization int[] mergeTwo(int[] nums1, int[] nums2) { int[] arr = new int[nums1.length+nums2.length]; int index_1=0;...

how do I filter what I entered in the JTextField and display the filtered result?

java,string,jframe,jtextfield,indexoutofboundsexception
package javaisnotbannana; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.*; import javax.swing.*; public class Javaisnotbannana{ public static void main(String[] args) { window(); } //////////////////////////////////////////////////// public static void window() { JFrame window= new JFrame(); JPanel jp = new JPanel(); JLabel jl = new JLabel(); JTextField jt = new JTextField(30); JButton jb = new...

Why does java.lang.ArrayIndexOutOfBoundsException occur?

java,arrays,indexoutofboundsexception
I'm making an array that outputs a user's input in reverse order. My program works however I keep getting this message, "Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: -1 at Reverse.main(Reverse.java:26)" I'm looking at line 26 which is, "System.out.println(number[x]);" but I don't see what's the matter with this. Why is this occurring?...

IndexOutofBoundsException: I cant solve it

java,indexoutofboundsexception
Im trying to do a basic java task, there are ships and i have to give the coordinates of them using an import file in which there are characters representing the movements of the ships. (N = +1 to North, S= +1 to South, E= +1 to East, W= +1...

Java ArrayIndexOutOfBounds

java,exception,indexoutofboundsexception
Currently working on a student project. I want to figure out the highest number and sort it by bubble sort, the number is parsed from a JLabel, but I get this error everytime. Here is a code snippet: JLabel[] wuerfelsummen = new JLabel[7]; wuerfelsummen[0] = player1_wuerfelsumme; wuerfelsummen[1] = player2_wuerfelsumme; wuerfelsummen[2]...

ArrayIndexOutOfBounds only at print

java,indexoutofboundsexception
I dont understand why this is happening. without the print statement the code works fine but when i try to print the elements i get ArrayIndexoutOfBounds. For example if i try to feed 3 elements i get exception thrown. can anyone please explain class MyClass { int search(OtherClass obs,target) {...

IndexOutOfBoundsException in my Android Listview adapter

android,listview,indexoutofboundsexception
I keep getting this IndexOutOfBoundsException, but can't seem to figure out what's causing it. My listview has an adapter with a list of objects, and the objects are removed based on a timestamp. The removal is done inside the getView method. Once an item is removed, I call notifyDataSetChanged(). The...

ArrayIndexOutOfBoundsException when comparing arrays

java,arrays,indexoutofboundsexception
Whenever I try to run this method to compare arrays I always get an ArrayIndexOutOfBoundsException. What am I doing wrong? public static boolean areIdentical(int[] m, int[] n) { //write a loop that compares each individual element of the two arrays. //if a mismatch is found, return false boolean identical =...

how solve ArrayIndexOfBoundsException

android,indexoutofboundsexception
I'm trying to develop a ListView with points and date from a game. But i want to put a picture next to each point. these images i have in an array, but when i execute the app it goes slow, the app stops and finish and it shows ArrayIndexOfBoundsException length=...

Unable to store object array length in Java

java,arrays,object,indexoutofboundsexception
I'm learning basic Java and I'm having a little trouble with object arrays. Some background on this code: I have a separate class called Point1, a simple point on a Cartesian plane, the properties of which that are relevant to this question being: 2 private integer variables _x and _y...

Connecting more than one Client to server: ArrayIndexOutOfBoundsException: 0

java,sockets,server,indexoutofboundsexception
I hope you can help me with my problem. I have a ServerClass and a ClientClass, and I am able to connect these two Programms. But if I want to conncect more than one Client to my Server over the same Virtutal Machine I receive following error: java.lang.ArrayIndexOutOfBoundsException: 0 I...

2D Array(Ragged) - Print Each Column Sum

java,arrays,for-loop,multidimensional-array,indexoutofboundsexception
I'm trying to calculate the column-wise sum of a 2D array. For this 2D array: int[][] array = {{1,2,3,4},{5,6,7,8},{9,10,11,12}}; I have no trouble printing each column sum. Here is my code which does that int total; for (int col = 0; col < array[0].length; col++) { total = 0; for...

ListView Footer causes ArrayIndexOutOfBoundsException

java,android,android-listview,indexoutofboundsexception,baseadapter
I've a ListView with a footer (simple LinearLayout with a TextView and a ImageView), and a BaseAdapter with 2 View types: @Override public int getViewTypeCount() { return 2; } My problem is when I scroll the list to the bottom and reach the footer because this exception is thrown: java.lang.ArrayIndexOutOfBoundsException:...

Change value of an index in an array, shift indexes starting at old index to the right, while leaving all indexes to the left intact

c#,arrays,indexoutofboundsexception
I have an array and I have a new value I want to insert into my array at an index where it will be less than those to the left of it, and greater than those to the right of it. I only care about 10 indexes, old values that...

Delphi, Lazarus - Listbox out of bound (0) TString

delphi,listbox,indexoutofboundsexception,lazarus,tstringlist
I simply can't seem to make any sense of the following error. Listbox out of bound (0) TString I have a form or window with a listbox and following code is supposed to work with it. It suppose to get a list of strings from an ini file and set...

Getting IndexOutOfRangeException without going out of the bounds of the array

c#,encryption,indexoutofboundsexception
So I have the code bellow to create an encrypted string using orgTxt and rndTxt, when I debug the code in Visual Studio I get an error of IndexOutOfRangeException in the second for loop. I check the value of the index with breakpoints and it seems perfectly in range, anyone...

Java.lang.ArrayIndexOutOfBoundException - AlertDialog

java,android,alertdialog,indexoutofboundsexception
I'm trying to build an app where if user click a button, it will shows an alertdialog with multiChoiceItems, I assigned the value of the option in multiChoiceItems from an ArrayList (which has been converted to arrayed string), but when I tried to click the button, the program is error...

Filling in polygon with my polygon fill algorithm give an out of bounds error

java,polygon,indexoutofboundsexception,fill
I am creating a program that takes draws a polygon and then fills the polygon with green. I am currently having an issue with the algorithm I have written as it only fills the top half of the polygon and then I get an IndexOutOfBounds error. Here is the code...

getting ArrayIndexOutOfBoundsException java

java,indexoutofboundsexception
my program calculates some stuff using multi-threading. I've tested it while giving the array a hardcoded length like 10, and my program works fine. However the way i'm doing it now using 'length', I am getting an "array out of bounds exception" on this line: array[i] = Integer.parseInt(splited[i]); before i...

Coordinate Out Of Bounds Exception With BufferedImage

java,image,swing,indexoutofboundsexception
Right now i am trying to make a game. I am having problems with loading my images. To do so I have to give an image to the removeImageBackground(BufferedImage img, Color tc) method in my Main class. Basically what this method does is take the image specified in the parameters...

Pattern Matcher gets ArrayIndexOutOfBoundsException: 0

java,junit,pattern-matching,indexoutofboundsexception
Here is the pseudocode of what I'm trying to do: procedure naive(T, P): result = { } for s = 0 to n – m match = true     for j = 0 to m – 1 if T[s+j] ≠ P[j] match = false if match result = result + {s} Here's what...

reading from file by .nextLine

java,indexoutofboundsexception
Im getting the following error when i run my program. It runs through the first line in the file but when it goes back to the loop in the main method to process the second line this is what i get. java.lang.ArrayIndexOutOfBoundsException: 1 at Popcorn.barGraphByLine(Popcorn.java:94) at Popcorn.main(Popcorn.java:31) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)...

Index out of bounds when using an copy of the variable [closed]

java,arraylist,indexoutofboundsexception
I can't get my head wrapped around this, so I hope that you guys have an good explanation of why this code isn't working. I've got an ArrayList of Point inside my Warehouse class. This piece of code works right (it's inside an another class than the Warehouse): Point lastPoint...

How to repeat the data from array Start data up to End data and again Start data in IOS objective c

ios,objective-c,arrays,uitableview,indexoutofboundsexception
I want to repeat the data while loading from array Start data up to End data and again Start data in IOS objective c. I have implemented the following code. I have use @try { } @catch to Handel the exception and stop to crash from index 0 beyond bounds...

Java: importing from text file to ArrayList - out of bounds errors

java,arraylist,indexoutofboundsexception
I am a student learning java and I am having a tough time trying to figure out why i am getting an out of bounds error. Any input on how to code the openFileList(); method would be extremely helpful. The precise error is : java.lang.IndexOutOfBoundsException: Index: 0, Size: 0 at...

My program throws an ArrayIndexOutOfBoundsException, but only sometimes

arrays,indexoutofboundsexception,selection-sort
I'm taking a computer science class at my high school, and we learned a lesson on selection sort today. I wrote a program (it's probably clumsy, but please bear with me, I'm learning) and it works in that it sorts, but sometimes it throws an ArrayIndexOutOfBoundsException. Only sometimes. I don't...

indexOutOfBoundsException with arraylists deletion

java,arraylist,indexoutofboundsexception
I am writing a space invaders knock off in java and I am almost done the actual working parts but I keep on getting this error: Exception in thread "AWT-EventQueue-0" java.lang.IndexOutOfBoundsException: Index: 0, Size: 0 at java.util.ArrayList.rangeCheck(ArrayList.java:653) at java.util.ArrayList.remove(ArrayList.java:492) at GamePanel.shotDelete(SpaceInvaders.java:261) at GamePanel.shieldHit(SpaceInvaders.java:198) at SpaceInvaders.actionPerformed(SpaceInvaders.java:44) at javax.swing.Timer.fireActionPerformed(Timer.java:313) at...

Array indexoutofboundsException:3

java,arrays,for-loop,indexoutofboundsexception
Can't figure out why my int[][] totalOpenness = new int[n][n];array continously goes out of bounds exception:3. My calculations of my public static void openfactor(char[][] mazeValue, int n) method are working fine; however, I get an array index out of bounds error on the following 2 lines inside my openfactor(char[][] mazeValue,...

jTable populating and refreshing ArrayIndexOutOfBoundsException

java,jtable,indexoutofboundsexception,swingworker
I have below SwingWorker for populate the jTable1. And i have button for executing this task. public class WorkerTime extends SwingWorker<Void, Void> { protected Void doInBackground() throws Exception { DefaultTableModel model1 = (DefaultTableModel) jTable1.getModel(); model1.setRowCount(0); for (int i = 0; i < 5; i++){ model1.addRow(new String[]{"a","a","a","a","a","a","a","a","a","a","a"}); model1.fireTableDataChanged(); } return null;...

What's wrong with this program to add three numbers in an array to get 30

java,indexoutofboundsexception
I want to add together three odd numbers less than 15 to get 30. Here is my code: import java.util.*; public class odd { public static void main(String args[]) { int n[]={1,3,5,7,9,11,13,15}; int a,n1,n2,n3; Random rand=new Random(); do { n1=n[(rand.nextInt(8)+1)]; n2=n[(rand.nextInt(8)+1)]; n3=n[(rand.nextInt(8)+1)]; a=n1+n2+n3;}while(a!=30); System.out.println(n1); System.out.println(n2); System.out.println(n3); } } I'm getting...

getting Arrayindexoutofboundsexception error [closed]

java,indexoutofboundsexception
I am reading a text file line by line, assigning each line to a string and parsing the string to read individual digits and assigning to them to a two dimensional matrix. I keep getting Arrayindexoutofboundsexception even though i'm checking that i am not out of bounds of my array...

Out of bounds exception when started using enums

java,enums,indexoutofboundsexception
I'm trying to have a program that maps terrain in java. Just now it's flagging an error in the main program: Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0 at Map.run(Map.java:35) at Terrain.run(Terrain.java:31) at Terrain.main(Terrain.java:10) I've just started using enum and it's only started t flag up when I implemented some into...

Substring strange Bounds?

java,string,substring,indexoutofboundsexception
So, I am trying to figure out why String.substring(int startIndex) allows a start index that is out of bounds and does not throw OOB exception? Here is the code I was testing this with : public class testSub { public static void main(String[] args) { String testString = "D"; String...

Why doesn't C++ detect when out of range vector elements are accessed with the [ ] operators by default?

c++,vector,indexoutofboundsexception
I understand that arrays are a primitive class and therefore do not have built in methods to detect out of range errors. However, the vector class has the built in function .at() which does detect these errors. By using namespaces, anyone can overload the [ ] symbols to act as...

IndexOutOfBoundException using java.util.Vector

java,arrays,dynamic,vector,indexoutofboundsexception
I have a problem using java.util.Vector and java.util.ArrayList. I know the capacity or better how many elements will be saved within the vector. So i initialized a java.util.List using an implementation of it leveraging the constructor new Vector<?>(int capacity). After the initialisation of the List, I used the method set(index,...

Python: How to check the value of a non-existent list element without getting IndexError?

python,list,if-statement,indexing,indexoutofboundsexception
I'm using Python's one-line conditional thus: x = 'foo' if myList[2] is not None else 'bar' to assign to x the value of an item at a certain index of a list - if and only if it exists - and a different value if it doesn't. Here's my challenge:...

Java Array Index out of Bounds Exception (-1)?

java,arrays,indexoutofboundsexception
I realise that this question has been asked before, but I was unable to understand much of the answers that I read. I have been working on this code for a while: static ArrayList<String> psalmsTitlesArray = new ArrayList<>(47); static ArrayList<String> psalmsNumbersArray = new ArrayList<>(47); static String psalmTextFileArray[] = new String[47];...

Array List Error

java,arrays,arraylist,indexoutofboundsexception
ArrayList aList = new ArrayList(); public void AddPerson() { String n = JOptionPane.showInputDialog(null, "Please Enter Name"); String a = JOptionPane.showInputDialog(null, "Please Enter Name"); String p = JOptionPane.showInputDialog(null, "Please Enter Name"); PersonInfo person = new PersonInfo(n, a, p); aList.add(person); } public void Search(String n) { for (int i = 0; i...

Error: java.lang.ArrayIndexOutOfBoundsException: 1, how can be handled

java,indexoutofboundsexception
how can be handle the error in this code which give out this message java.lang.ArrayIndexOutOfBoundsException: 1 in order to send packet from client to server using udp socket public class DatagramServer { private final static int PACKETSIZE = 100 ; public static void main( String args[] ) { // Check...

Netty: Weird IndexOutOfBoundsException: readerIndex + length exceeds writerIndex

netty,indexoutofboundsexception
I am currently sending different packets through netty and I'm very often getting exceptions like these when receiving them: java.lang.IndexOutOfBoundsException: readerIndex(39) + length(32) exceeds writerIndex(64): UnpooledUnsafeDirectByteBuf(ridx: 39, widx: 64, cap: 2048) at io.netty.buffer.AbstractByteBuf.checkReadableBytes(AbstractByteBuf.java:1166) at io.netty.buffer.AbstractByteBuf.readBytes(AbstractByteBuf.java:655) at <snip>.PacketDataHolder.readString(PacketDataHolder.java:79) ...... or...

OutOfBoundsException with ALS - Flink MLlib

indexoutofboundsexception,recommendation-engine,flink
I'm doing a recommandation system for movies, using the MovieLens datasets available here : http://grouplens.org/datasets/movielens/ To compute this recommandation system, I use the ML library of Flink in scala, and particulalrly the ALS algorithm (org.apache.flink.ml.recommendation.ALS). I first map the ratings of the movie into a DataSet[(Int, Int, Double)] and then...

User Cannot Enter Text, Index Out Of Bounds Exception

java,arraylist,javafx,textfield,indexoutofboundsexception
My code runs but when the user inputs text into the text field I am getting an Out Of Bounds Exception. I think it has something to do with this line of code where I give the empty box a value: int express = (str != null && !"".equals(str)) ?...

Java ArrayIndexOutOfBound

java,arrays,exception,indexoutofboundsexception
I am currently working on a student project and everytime I get this error: ArrayIndexOutOfBoundsException: 7. Can someone see where it occurs and how I can fix it? I know the code looks messy but its just for me. The size of the array is 7. public void actionPerformed(ActionEvent e)...

Is there a way to force java to ignore an Index out of bounds exception

matrix,indexoutofboundsexception
If, say, I want to iterate through a matrix and check the contents at the positions around the one I'm at, is there a way to check all those positions, and should one or more of them be out of bounds, it just skips that part and moves on?

Error with receiving strings to list

java,indexoutofboundsexception
It's a program to receive n strings to list and find duplicate's count for each string and print string and number of duplicates in a map. I get this error and i can't find the problem! Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 5, Size: 5 at java.util.ArrayList.rangeCheck(Unknown Source) at java.util.ArrayList.get(Unknown...

Android -ArrayindexboundException in setting a byte[] of image from database to Listview

java,android,sqlite,listview,indexoutofboundsexception
I need to insert and retrieve these from SQLite database and set to image view in a custom ListView. But running the app throws an ArrayIndexOutOfBoundException So I tried making j=0 outside while loop. But still causes a ArrayIndexOutOfBoundException in line: Bitmap b1=BitmapFactory.decodeByteArray(img[j], 0, img.length); What should I do? I...

index out of bound exception in java when accessing index of list

java,list,indexoutofboundsexception
I have a list and when I try to access the index of that list it gives index out of bound exception and when I print the value of that index in another method ,Its showing the result I can't understand when value is there at that particular index why...

TextArea.continueCursor(TextArea.java:331) / ArrayIndexOutOfBoundsException: 16

user-interface,libgdx,thread-safety,indexoutofboundsexception
What could be the cause of this error? (Can't figure it out) Exception in thread "LWJGL Application" java.lang.ArrayIndexOutOfBoundsException: 16 at com.badlogic.gdx.scenes.scene2d.ui.TextArea.continueCursor(TextArea.java:331) at com.badlogic.gdx.scenes.scene2d.ui.TextArea.calculateOffsets(TextArea.java:278) at com.badlogic.gdx.scenes.scene2d.ui.TextField.draw(TextField.java:283) at com.badlogic.gdx.scenes.scene2d.Group.drawChildren(Group.java:124) at com.badlogic.gdx.scenes.scene2d.Group.draw(Group.java:58) at...

importing a csv file into oracle database using java

java,eclipse,csv,oracle10g,indexoutofboundsexception
I am getting the following error Java.lang.ArrayIndexOutOfBoundsException: 0 at oracle.jdbc.driver.OracleSql.main(OracleSql.java:1614) I am using eclipse indigo and oracle 10g.how can i fix this problem.can anyone help me ? i want to load a csv file into oracle database.. i've created a table named zt with three columns (id, s_date, data) CSV...

Print Size of args[] array - out of bounds exception error

java,indexoutofboundsexception,args
I understand why an outofbounds error is thrown, but not why it is in this case. In the course text book, some exercises include writing code to "print out its' command line argument" and "add its two command line arguements" The two codes I've written are: public class AddToCommandLine {...

Getting IndexOutOfBoundException While iterating Arraylist in for loop

java,arraylist,indexoutofboundsexception
I am getting java.lang.IndexOutOfBoundsException while Iterating the Arraylist by using For loop. I knew it why i am getting this exception but i don't the solution to fix this issue. I have to divide the string based up on the values in the Arraylist. For this i have used the...