NTNUJAVA Virtual Physics Laboratory
Enjoy the fun of physics with simulations!
Backup site http://enjoy.phy.ntnu.edu.tw/ntnujava/

Easy Java Simulations (2001- ) => Questions related to EJS => Topic started by: lookang on August 27, 2009, 04:59:31 pm

Title: How come cannot assign yv[j] to POS Y of a text field?
Post by: lookang on August 27, 2009, 04:59:31 pm

Hi prof,

i encountered a strange problem and i manage to isolate the cause.

The cause is
when i assign a yv[j] to the POS Y of a text field
it compile ok
but when i mouse over the array dots

the Ejs console starts to show error message. How to solve or overcome this problem? Thanks!

"RMI registry started at port: 2008
EjsConsole server is ready to listen at port: 2008
Running selected program
 C:/Program Files/Java/jre6//bin/java -Xmx256m -classpath bin/comSun.jar;bin/osp.jar;bin/ejs_lib.jar;bin/bsh.jar;bin/ejs.jar;bin/extensions/djep.jar;bin/locales.jar -Dcodebase=. -Dhome=D:\Shared\EasyJavaSimulation\EJS_4.2_090807\EJS_4.2\workspace org.colos.ejs.osejs.Osejs -lastFile -lookAndFeel javax.swing.plaf.metal.MetalLookAndFeel -decorateWindows -screen 0
cHotEqn V 4.02 cHotEqn
   at sun.reflect.GeneratedMethodAccessor13.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
   at java.lang.reflect.Method.invoke(Unknown Source)
   at org.colos.ejs.library.control.MethodWithOneParameter.invoke(Unknown Source)
   at org.colos.ejs.library.control.GroupVariable.propagateValue(Unknown Source)
   at org.colos.ejs.library.control.EjsControl.doTheUpdate(Unknown Source)
   at org.colos.ejs.library.control.EjsControl.update(Unknown Source)
   at org.colos.ejs.library.Animation.update(Unknown Source)
   at org.colos.ejs.library.Animation.updateWhenIdle(Unknown Source)
   at org.colos.ejs.library.control.EjsControl.updateSimulationWhenIdle(Unknown Source)
   at org.colos.ejs.library.control.ControlElement.variableChanged(Unknown Source)
   at org.colos.ejs.library.control.displayejs.ControlPoligon.interactionPerformed(Unknown Source)
   at org.opensourcephysics.displayejs.AbstractInteractiveElement.invokeActions(Unknown Source)
   at org.colos.ejs.library.control.swing.ControlPlottingPanel.handleMouseAction(Unknown Source)
   at org.opensourcephysics.display.InteractivePanel$IADMouseController.mouseMoved(Unknown Source)
   at java.awt.Component.processMouseMotionEvent(Unknown Source)
   at javax.swing.JComponent.processMouseMotionEvent(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.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)
Caused by: java.lang.ArrayIndexOutOfBoundsException: -1

for example i didn't copy the whole chunk of error message

Title: Re: How come cannot assign yv[j] to POS Y of a text field?
Post by: Fu-Kwun Hwang on August 27, 2009, 05:53:14 pm
Have you defined a variable "j" and assigned a proper value?

Title: Re: How come cannot assign yv[j] to POS Y of a text field?
Post by: lookang on August 27, 2009, 08:15:38 pm
it appears j is defined as a integer and assigned a number 0 in the variables page.


Any other possible insights?

by the way, what does the error message in ejs console by "java.lang.ArrayIndexOutOfBoundsException: -1" mean?

but the n is equal 11, should be enough? hmmmmmmmmmmmmmm

Caused by: java.lang.ArrayIndexOutOfBoundsException: -1
   at users.sgeducation.lookang.weexvav17rebuildworkingold_pkg.weexvav17rebuildworkingold._method_for_showcoordinates_l2_y(weexvav17rebuildworkingold.java:510)
   ... 34 more

Title: Re: How come cannot assign yv[j] to POS Y of a text field?
Post by: Fu-Kwun Hwang on August 27, 2009, 09:57:38 pm
The error message I found is different from what you have shown.
I found there is a strange character at the end of last variable at first variable page: vti
I removed that character and it compiled without any error.
Please check out the attached file.

Title: Re: How come cannot assign yv[j] to POS Y of a text field?
Post by: lookang on August 27, 2009, 10:09:35 pm
U have to select in the drop down list edit v-t graph

move ur mouse over any of the green objects

the error continues to appear even on your attachment of my xml. ;D

by the way, i notice the time stamp is interesting, it is 11.09 pm instead of 10:09:35 PM
is the codes modified correctly? ;D

Title: Re: How come cannot assign yv[j] to POS Y of a text field?
Post by: Fu-Kwun Hwang on August 29, 2009, 03:44:46 pm
You can find out the following from ejs console:
Caused by: java.lang.ArrayIndexOutOfBoundsException: -1
at users.lookang.weexvav17rebuildworkingold_pkg.weexvav17rebuildworkingold._method_for_showcoordinates_l2_y(weexvav17rebuildworkingold.java:624)

Open weexvav17rebuildworkingold.java (under output directory) check out line 624:
which is:
  public double _method_for_showcoordinates_l2_y () { return yv[j]; }

The problem is due to j has been assign a value which is not acceptable: for example: -1

for example: you assign Element property to j in ParticleSet_movable2
which mean that j will be assign value -1 when mouse is not move to those particles (not selected).
You might have other setting cause similar effect.

You can change the setting from yv[j]  to yv[jid]: and defind a new variable jid
add the following code at "Fixed Relation page)
if(j>-1 && j<n)jid=j;
else jid=0;// or other valid values.

Title: Re: How come cannot assign yv[j] to POS Y of a text field?
Post by: lookang on August 29, 2009, 04:04:44 pm
thanks a million,  the cause of the problem was bugging me every day. I can't stop thinking about it. LOL

U helped me overcome this problem.

My reflection:
I roughly know it was the ArrayIndexOutOfBoundsException: -1 giving problem,  but i didn't know -1 was a illegal state in java ArrayIndexOutOfBoundsException: -1, thus unable to overcome it myself. ;D   I was trying many ways but just can't solve it alone.


Title: Re: How come cannot assign yv[j] to POS Y of a text field?
Post by: lookang on December 01, 2009, 09:34:59 pm
i have learnt how to solve the array out of bound error!!!!

i solved a problem on my own, reflecting on this post. Ya!.

i download any java editor, i google and http://www.jedit.org/index.php?page=download came up.

after installing

i browsed to the error file
LookangVernierCaliper04FKH.java for example
look for the error line it was, say line 803

with jedit is easy to locate that line,

for example the old code is //xp=xm2t[vs]; // this is the way to determine position of lower scale pointer

that means vs jumps to a illegal value from what was defined in the variable page

for my example xm2t is defined as an array n2t where n2t is defined as 11.

insert and modify logically . my example is

// adding this code to solve array out of bound error 803
// http://www.phy.ntnu.edu.tw/ntnujava/index.php?topic=1183.0 solution discussed
if(vs >  -1 && vs< n2t)vsidarray=vs;
else vsidarray=0;// or other valid values.

// this line is causing array out of bound error 803
//xp=xm2t[vs]; // comment that line that is causing the array out of bound error
xp=xm2t[vsidarray]; // modify logically to this

this way, no more array error out of bound 12 because n2t is 0 to 10.

Title: How to debug the run time error
Post by: Fu-Kwun Hwang on December 02, 2009, 09:20:06 am
Yes, you find out the way to debug the run time error when developing EJS simulation.

The java console will display the filename and line number where run time error occurs.
You will find the java file under EJS output subdirectory.

You can use any text editor to debug it (it will be better if the editor can display line number).

P.S. EJS can display syntax error in ejs console, but EJS can not find out run time error.