Win a copy of Micro Frontends in Action this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

ArrayIndexOutOfBoundsException:4

 
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:


 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • 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.
 
Marshal
Posts: 70351
283
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic