0

I really need some help on this one, been struggling with this for days.

I have 4 jComboBox's in my code and the one is filled with clients and the other three are left blank. I have added an action listener on the clients jcombobox so that when the user selects a client, it calls a class and information is retrieved from the database and stored in a 2 dimensional array, after that the other three jcombobox's are filled with stuff like invoice id's amount's and dates.

So what I am trying to do is empty the jcombobox boxes in the action listener so that they when the class is called specific client information can be added to the other box's. this works perfect the first time round but the second I try and change a client from the first jcombobox I get this error:

Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: -1

I am using jCombobox.removeAllItems() and jCombobox.revalidate() on the last three boxs.

please help if you can, much appreciated.

mcruz
  • 1,534
  • 2
  • 11
  • 14
Captain
  • 15
  • 3
  • http://stackoverflow.com/questions/5554734/what-causes-a-java-lang-arrayindexoutofboundsexception-and-how-do-i-prevent-it – Tunaki Apr 28 '16 at 21:59
  • If the above link didn't solve your problem, I would like you to post your action listener method and I'll take a look at it. – Ethan Moore Apr 29 '16 at 00:13
  • @EthanMoore thanks, it didnt help but i fixed that error. i am however getting a different error which is being caused by the removeAllItems function. here is the action listener: jComboBox1.addActionListener (new ActionListener () { public void actionPerformed(ActionEvent e) { System.out.println("finding the error"); jComboBox2.removeAllItems(); jComboBox3.removeAllItems(); jComboBox4.removeAllItems(); jComboBox2.revalidate(); jComboBox3.revalidate(); jComboBox4.revalidate(); setText(); }}); and the error code is: Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException – Captain Apr 29 '16 at 16:40
  • Yeah, so, if I understand correctly, you're constructing your action listener is a little unconventional. Also, I would appreciate it if you would format your text. Just for sake of understanding. :P So, usually when you get `NullPointer`, it's because the item you're taking from is blank. Try adding a `ComboBoxModel` to certain `jComoBox`es. . It would make your handling of many different objects much easier. Take a look at [link](https://docs.oracle.com/javase/tutorial/uiswing/events/actionlistener.html) and [link](https://docs.oracle.com/javase/7/docs/api/javax/swing/ComboBoxModel.html) – Ethan Moore Apr 29 '16 at 18:34
  • Also, if you'd like, we could make a google docs co-edit and I can look at your code easier there, if necessary. Hope I've helped thus far! – Ethan Moore Apr 29 '16 at 18:36
  • 1
    @EthanMoore thanks so much for your help, sorry about the code being so hard to read, i ran out of characters and didn't know i could just use another comment. don't normally post here as I am usually able to find my answers in other peoples questions, ill go try add a ComboBox model. if not i would appreciate a docs co edit, never used it before but how hard could that be – Captain Apr 29 '16 at 19:03
  • It's not hard at all, if you have a gmail account. You just make a document on Google Drive, and then enable sharing, and send the link to me, and we can work on this together. :D And I applaud you trying to figure out your own things. :D – Ethan Moore Apr 29 '16 at 19:06
  • @EthanMoore its not working either, do you want to give me your email an i will create a link that's linked to your email and email it to you – Captain Apr 29 '16 at 19:25

0 Answers0