• Post Reply Bookmark Topic Watch Topic
  • New Topic

ArrayIndexOutOfBoundsException:4  RSS feed

 
Alzecha Maris
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey there, I'm having a bit of trouble with this project:

We're given a text file of 5 students, with 4 number grades following each name in a separate line. We have to use our main method to read the file, then perform calculations in the gradebook class. However, from what others in class have been saying the method we're using is archaic at best, involving Parallel arrays. We don't really seem to have any other option though, so I'm making due with what I can. But near what I'm hoping is the end of this code, I've encountered a problem, where it says the index that contains the grades for students is out of bounds.

I've rewritten the readFile method in my main in quite a few different ways, but no matter what I still get these errors. Could anyone help me understand what's going on? I'll post everything I can.
I also apologize if I'm a bit slow/incapable with this, this is my first time coding java in months unfortunately.





This here is the error I got:


 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Alzecha Maris wrote:This here is the error I got:



That error originates from line 64 of GradeBookDemo.java in the readFile(...) method.

Your GradeBookDemo.java posted here has 56 lines.

For someone to be able to help you, you need to post real code.

edit: corrected typo
 
Alzecha Maris
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I apologize for that, I omitted the upper parts of the code because it contains my personal information. I forgot that would mess up the line numbering. Line 64 translates to 47 in the code I posted. I'll edit that into the OP.
 
Campbell Ritchie
Marshal
Posts: 56525
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have altered the line numbers. You can find out how to do it here.

If you are getting that exception, it means you are trying to put a 5th value into a 4‑element array.
Remember a 4‑element array has index numbers 0…3.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!