[JTable] getValue throws ArrayOutOfBoundException

  • Themenstarter Themenstarter mickedplay
  • Beginndatum Beginndatum
M

mickedplay

Gast
Hey.

Beim Abfragen des Wertes in der Zelle, wirft mein Programm immer ne ArrayOutOfBoundsException aus. Jemand eine Idee, woran das liegen könnte?#

Exception:
Java:
Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 3 >= 3
	at java.util.Vector.elementAt(Unknown Source)
	at javax.swing.table.DefaultTableColumnModel.getColumn(Unknown Source)
	at sun.swing.SwingUtilities2.convertColumnIndexToModel(Unknown Source)
	at javax.swing.JTable.convertColumnIndexToModel(Unknown Source)
	at javax.swing.JTable.getValueAt(Unknown Source)
	at play.mickedplay.dlcenter.components.Manager.getValueAt(Manager.java:57)
	at play.mickedplay.dlcenter.components.Comp_JPanel.actionPerformed(Comp_JPanel.java:82)
	at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
	at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
	at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
	at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
	at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
	at java.awt.Component.processMouseEvent(Unknown Source)
	at javax.swing.JComponent.processMouseEvent(Unknown Source)
	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(Unknown Source)
	at java.awt.LightweightDispatcher.dispatchEvent(Unknown 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.dispatchEventImpl(Unknown Source)
	at java.awt.EventQueue.access$500(Unknown Source)
	at java.awt.EventQueue$3.run(Unknown Source)
	at java.awt.EventQueue$3.run(Unknown Source)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
	at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
	at java.awt.EventQueue$4.run(Unknown Source)
	at java.awt.EventQueue$4.run(Unknown Source)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
	at java.awt.EventQueue.dispatchEvent(Unknown Source)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.run(Unknown Source)

Code:
Java:
public static String getValueAt(int index, int row)
	{
		JTable table = getTable(index).files;
		String value = table.getValueAt(row, 3).toString();   <-------- (table ist nicht null)
		return value;
	}
JTable.png
Ich möchte einfach nur die Werte der einzelnen Zellen abrufen. In der ersten (links) Boolean, in der zweiten (mitte) String und in der letzten (rechts) Integer.

Zusatzfrage:
Weiß zufällig jemand, wie ich die Breite der Spalten ändern kann? Ist aber nicht so wichtig.

Danke 😀
 
Ersetze table.getValueAt(row, 3).toString() durch table.getValueAt(row, 2).toString().
Da deine tabelle 3 Spalten hat, hat der Vector, der die Daten jeder Zeile speichert, 3 Elemente, die mit den Indices 0 bis 2 abgefragt werden können.
Der Hinweis, das table nicht null ist, ist überflüssig. Wenn das der Grund für die Exception wäre, würde eine NullPointerException geworfen werden.
 

Neue Themen


Zurück
Oben