java.lang.ArrayIndexOutOfBoundsException

Hello,

I am getting this error in the following situation:

  • I have a global method that creates new records in whatever form. The method takes care of several things like starting a transaction etc. and finally shows a dialog where you can enter the data. The dialog also allows to browse through all records that already exist, so it loads a foundset first.
  • On the form itself there is also a button to create a new record, so you can hit a button in a table view, see a dialog where you can enter data and then click on a button inside the dialog to create a new record.
  • The problem is, that you can do that only once. If you hit the button “New” another time, you get this error

Here is the code part where it goes wrong:

// Variables get the values before this part, so here just as an explanation:
var fs; // a foundset
var form; // a form name
var pkField; // the name of the PK column

...

if (!fs || forms[form].controller.getMaxRecordIndex() == 0)
{
	// there is no foundset or no records at all
	forms[form].controller.loadAllRecords();
	forms[form].controller.newRecord();
	forms[form].controller.saveData();

	// create a foundset "manually"
	var id = forms[form][pkField];
	var test = new Array()
	test[0] = id;
	fs = databaseManager.convertToDataSet(test);
	// foundset laden
	forms[form].controller.loadRecords(fs);
}
else
{
	// load foundset
	if (fs != forms[form].foundset) // didn't have that before, thought it helps
	{
		forms[form].controller.loadRecords(fs);
	}
	// create new record
	forms[form].foundset.newRecord();  // HERE IT'S OVER
	currentcontroller.saveData();
}

...

And this is the error:

java.lang.ArrayIndexOutOfBoundsException: 1 >= 0java.lang.ArrayIndexOutOfBoundsException: 1 >= 0
	at java.util.Vector.elementAt(Unknown Source)
	at javax.swing.DefaultListModel.getElementAt(Unknown Source)
	at com.servoy.j2db.dataui.DataField$a.valueToString(Unknown Source)
	at javax.swing.JFormattedTextField$AbstractFormatter.install(Unknown Source)
	at javax.swing.text.DefaultFormatter.install(Unknown Source)
	at javax.swing.text.InternationalFormatter.install(Unknown Source)
	at com.servoy.j2db.dataui.DataField$a.install(Unknown Source)
	at javax.swing.JFormattedTextField.setFormatter(Unknown Source)
	at com.servoy.j2db.dataui.DataField.setFormatter(Unknown Source)
	at javax.swing.JFormattedTextField.setValue(Unknown Source)
	at javax.swing.JFormattedTextField.setValue(Unknown Source)
	at com.servoy.j2db.dataui.DataField.for(Unknown Source)
	at com.servoy.j2db.dataui.DataField.firePropertyChange(Unknown Source)
	at javax.swing.JFormattedTextField.setValue(Unknown Source)
	at javax.swing.JFormattedTextField.commitEdit(Unknown Source)
	at com.servoy.j2db.dataui.DataField.commitEdit(Unknown Source)
	at com.servoy.j2db.dataui.DataField.stopUIEditing(Unknown Source)
	at com.servoy.j2db.dataprocessing.d.long(Unknown Source)
	at com.servoy.j2db.dataui.l.stopUIEditing(Unknown Source)
	at com.servoy.j2db.n.stopUIEditting(Unknown Source)
	at com.servoy.j2db.FormPanel.cY(Unknown Source)
	at com.servoy.j2db.dataui.SpecialTabPanel$a.ah(Unknown Source)
	at com.servoy.j2db.dataui.SpecialTabPanel.stopUIEditing(Unknown Source)
	at com.servoy.j2db.dataprocessing.d.long(Unknown Source)
	at com.servoy.j2db.dataui.l.stopUIEditing(Unknown Source)
	at com.servoy.j2db.FormPanel.a(Unknown Source)
	at com.servoy.j2db.FormPanel.a(Unknown Source)
	at com.servoy.j2db.FormPanel.a(Unknown Source)
	at com.servoy.j2db.FormPanel$b.actionPerformed(Unknown Source)
	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.dispatchEvent(Unknown Source)
	at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
	at java.awt.Dialog$1.run(Unknown Source)
	at java.awt.Dialog.show(Unknown Source)
	at java.awt.Component.show(Unknown Source)
	at java.awt.Component.setVisible(Unknown Source)
	at com.servoy.j2db.util.b.setVisible(Unknown Source)
	at com.servoy.j2db.k.setVisible(Unknown Source)
	at com.servoy.j2db.k.a(Unknown Source)
	at com.servoy.j2db.FormManager.a(Unknown Source)
	at com.servoy.j2db.scripting.JSApplication.js_showFormInDialog(Unknown Source)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.mozilla.javascript.NativeJavaMethod.call(NativeJavaMethod.java:289)
	at org.mozilla.javascript.ScriptRuntime.call(ScriptRuntime.java:1242)
	at org.mozilla.javascript.Interpreter.interpret(Interpreter.java:1942)
	at org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java:94)
	at com.servoy.j2db.scripting.e.call(Unknown Source)
	at org.mozilla.javascript.ScriptRuntime.call(ScriptRuntime.java:1242)
	at org.mozilla.javascript.Interpreter.interpret(Interpreter.java:1942)
	at org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java:94)
	at com.servoy.j2db.scripting.e.call(Unknown Source)
	at com.servoy.j2db.develop.debugger.k.a(Unknown Source)
	at com.servoy.j2db.develop.debugger.k.executeFunction(Unknown Source)
	at com.servoy.j2db.FormPanel.a(Unknown Source)
	at com.servoy.j2db.FormPanel.a(Unknown Source)
	at com.servoy.j2db.FormPanel$b.a(Unknown Source)
	at com.servoy.j2db.dataui.AbstractScriptLabel.a(Unknown Source)
	at com.servoy.j2db.dataui.AbstractScriptLabel.access$4(Unknown Source)
	at com.servoy.j2db.dataui.AbstractScriptLabel$5.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.dispatchEvent(Unknown Source)
	at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)

That looks like a textfield that has a valuelist attached but that valuelist is empty.
Still that error shouldn’t happen if i look at the code. Because that index value should be there. Because we first test for that…
So in youre case there must be something wrong with the displayvalues and the returnvalues of youre valuelist that is beneath the textfield..

The method shown is a global method that is used all over the place. Are you saying that I get this error because of some value list in the form that is currently used? I could check for that…

yes as far as i can see you press a button.
that causes the form to stop editting and then it goes wrong in a DataField that asks his ValueList for a element that belongs to the real value. (like and ID that translates to a name)

I will try to narrow that down. Thanks at first!