PDA

Visualizza la versione completa : [java] errore JComboBox


hannibal/p
14-02-2004, 21:23
ciao amici
perchè se lancio un metodo da un SelectionListener di un JComboBox ricevo questo errore??

java.lang.ArrayIndexOutOfBoundsException
at java.lang.System.arraycopy(Native Method)
at java.awt.Container.remove(Unknown Source)
at javax.swing.JLayeredPane.remove(Unknown Source)
at java.awt.Container.remove(Unknown Source)
at javax.swing.JRootPane.setContentPane(Unknown Source)
at javax.swing.JFrame.setContentPane(Unknown Source)
at Tabella.cerca(Tabella.java:797)
at Tabella.io(Tabella.java:906)
at Tabella$SelectionListener.actionPerformed(Tabella. java:920)
at javax.swing.JComboBox.fireActionEvent(Unknown Source)
at javax.swing.JComboBox.setSelectedItem(Unknown Source)
at javax.swing.JComboBox.setSelectedIndex(Unknown Source)
at javax.swing.plaf.basic.BasicComboPopup$ListMouseHa ndler.mouseReleased
(Unknown Source)
at java.awt.AWTEventMulticaster.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.plaf.basic.BasicComboPopup$2.processMo useEvent(Unknown So
urce)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent( Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(U nknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unkno wn Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForHierar chy(Unknown Source)

at java.awt.EventDispatchThread.pumpEventsForHierarch y(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)

C:\Documents and Settings\Administrator\Desktop\attivita>java Tabella funky
java.lang.ArrayIndexOutOfBoundsException
at java.lang.System.arraycopy(Native Method)
at java.awt.Container.remove(Unknown Source)
at javax.swing.JLayeredPane.remove(Unknown Source)
at java.awt.Container.remove(Unknown Source)
at javax.swing.JRootPane.setContentPane(Unknown Source)
at javax.swing.JFrame.setContentPane(Unknown Source)
at Tabella.cerca(Tabella.java:797)
at Tabella.io(Tabella.java:906)
at Tabella.access$000(Tabella.java:9)
at Tabella$SelectionListener.actionPerformed(Tabella. java:920)
at javax.swing.JComboBox.fireActionEvent(Unknown Source)
at javax.swing.JComboBox.setSelectedItem(Unknown Source)
at javax.swing.JComboBox.setSelectedIndex(Unknown Source)
at javax.swing.plaf.basic.BasicComboPopup$ListMouseHa ndler.mouseReleased
(Unknown Source)
at java.awt.AWTEventMulticaster.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.plaf.basic.BasicComboPopup$2.processMo useEvent(Unknown So
urce)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent( Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(U nknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unkno wn Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForHierar chy(Unknown Source)

at java.awt.EventDispatchThread.pumpEventsForHierarch y(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)

mauri@como
15-02-2004, 01:10
Come si fa a capire senza un pò di codice?
quello che è quasi certo è che hai associato il listener ad un item della comboBox il cui indice viene usato in modo scorretto lanciando l'eccezione..però senza saper altro...e dura!!

hannibal/p
15-02-2004, 10:27
ok mi spiego meglio


class SelectionListener implements ActionListener {
public void actionPerformed(ActionEvent e){

cerca();


}
}

il metodo cerca() serve a fare una ricerca su un database access, qundi apre la connessione al db fa la ricerca e chiude la connessione.

se io lancio questo metodo da un pulsante funziona perfettamente:

public void actionPerformed(ActionEvent evt){
Object source = evt.getSource();


if (source == cerca)
{
cerca();
}


ciao

mauri@como
15-02-2004, 11:18
Se non ho inteso male usi il metodo .getSource() per fare un confronto con l'item secelto dalla combo. è cosi?

Dalla combo ricevi "cerca"? qual'è il tipo di forma?

Per il tuo scopo non sarebbe meglio passare al listener direttamente l'item "cerca" (una stringa!)?
ti definisci una variabile globale String scelta nella classe e fai nel listener un test tipo if scelta=="cerca"..

il contenuto di una combo si prende con il metodo .getSelectedItem() che ti torna un oggetto a cui puoi fare un cast (in questo caso String) e confrontarlo con un altro oggetto (un altra stringa)

spero di essere stato chiaro
ciao :ciauz:

anx721
15-02-2004, 14:24
class SelectionListener implements ActionListener {
public void actionPerformed(ActionEvent e){

cerca();


}
}

se io lancio questo metodo da un pulsante funziona perfettamente:

public void actionPerformed(ActionEvent evt){
Object source = evt.getSource();

if (source == cerca)
{
cerca();
}


Cioè il secondo metodo funziona mentre il primo no?

hannibal/p
15-02-2004, 16:59
esatto
il primo è un JComboBox , il secondo e un JButton

anx721
15-02-2004, 17:16
Può dipendere da ciò che fai nel metodo cerca.

Loading