Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • 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:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

array out of bounds and adding double contact  RSS feed

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello and thank you for having a board to ask questions!

I am writing a phone book and have two issues.

Every time I try to edit or delete a contact I am getting array out of bounds error.
After I add the first contact, every contact after that grows exponentially.

Any major problems that you guys could point out for me research or figure out how to modify.

Thank you again for looking at my code below.



and

sorry I also have this
 
Sheriff
Posts: 23640
48
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's an awful lot of code for us to look through, when all we really want to know is "What line of code threw that exception?" When you get an exception, the thing to do is to look at the code which caused it. Starting a broad code review isn't the right way to debug.
 
Sheriff
Posts: 21421
94
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The error is thrown because of line 239 of the Gui class, which is A simple print out of index at that point shows it's -1. That means there is no selected element. The reason is quite clear:
When you press Edit it opens the Edit frame (tip: use modal JDialogs instead of JFrames). The Save button is added to this frame. If you press it you clear the list (dList.clear()), then fill it again. But the clearing will also trigger a selection change, as the selection changes from something to nothing (since there is nothing to select).

I've added a quick check against this; above line 239 I added "if (index == -1) return;". This will result into another error, this time on line 90: That's because you're trying to change each entry, but the list model is empty. Change this call into That gets rid of all the errors, but you still loose your selection.
 
Marshal
Posts: 59711
187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
. . . and welcome to the Ranch
 
Greg Gruic
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Paul Clapham wrote:That's an awful lot of code for us to look through, when all we really want to know is "What line of code threw that exception?" When you get an exception, the thing to do is to look at the code which caused it. Starting a broad code review isn't the right way to debug.



Sorry first time posting for Java help on a board. It makes sense and will keep this in mind next time!

Rob thanks for taking the time to dig through the long code and provide with help. JDialog is alot easier and a little shorter might I add, thanks for pointing it out.

You guys were a great help! Looking forward to many more posts and hopefully some contribution to up and coming programmers.

Thanks again,
Greg
 
Rob Spoor
Sheriff
Posts: 21421
94
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're quite welcome
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!