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

Code review  RSS feed

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can someone please test/review this code. I apologize if the code is unconventional as I am new to JAVA and learning as I go, but I would appreciate any constructive critisism.

The application is working as expected, however I have a bug which eludes me. If you add 2 records and delete record 1, the program will fail with the following:


Here is the full code, any help or tips would be greatly appreciated:
 
Ranch Hand
Posts: 178
2
Java MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you are trying to delete a object in JComboBox.
You deleting command is fine. But there is a problem.

After you have deleted a object in JComboBox, the selected item is changing implicitly. That's because JComboBox cannot find that previously selected item as it has been deleted. Therefore JComboBox select the previous item.
But you have override itemStateChanged() method. As the previously selected item is deselected and new item is selected, overridden method is called twice. (But it is not the problem here)


Here the variable 'selected' is the problem. If you select 2nd item selected=1. After you delete 2nd item, JVM calls itemStateChanged() method. Then comboBox.getItemAt(selected) will give runtime error as 'selected = 1'.
 
Gareth Billett
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Ramesh I see the issue.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!