RingJavafor Ring

Troubleshooting

The messages that people meet most often, what causes them and what to do. Each problem has the message as Ring or Java prints it.

Read the last lines of an error first: for a Java error they say which Java exception was raised and where (In java_do() In method join() in file ... is the Ring side of the call). For a Ring error the line number and the name of the function are given.

Starting#

Message or symptomCauseWhat to do
Error (E9) : Can't open file java.ringthe package is not installed in the Ring that runs the programextract ringjava.zip into the Ring folder (see Installing and distributing); ring --version shows which Ring runs
the JVM is not found, or a message about jvm.dll / libjvm.sono JDK was foundgive one JDK 17 or later with jUseJDK("...") before the first Java call, or set RINGJAVA_HOME or JAVA_HOME (the order is in Getting started); the JDK must be 64 bit like Ring
UnsatisfiedLinkError or a message about the Java bridgeringjava.jar is not next to the extensionthe jar is in ring/bin (Windows) or ring/lib (Linux) next to the library; jInfo() prints the places that were used
Linux: libring.so: cannot open shared object filethe loader does not know where Ring isexport LD_LIBRARY_PATH=$HOME/ring/lib (the library libring_java.so must also be built: sh extensions/ringjava/buildgcc.sh)
the option names of a call with named values are not found (Linux)paramnames.txt is not next to the jarit is copied with the jar by setup.ring and by the build scripts

Classes and packages#

Message or symptomCauseWhat to do
Error (R11) : Error in class name, class not found: arraylistthe package is not importedusing { "java.util" } before new ArrayList (or the dynamic API: jNew("java.util.ArrayList",[]))
Java Error: No generated classes for the package ...there are no Ring classes for that packagea package of the JDK is in libraries/javalib/generated; for a jar use jMavenClasses(...) or the generator
two packages that have a class with the same name (java.awt.Label and a JavaFX Label)one Ring class name can not have two meaningsimport only one of them, or use jNew("full.class.Name"); the message of the import names the classes
a class is called EventMouseEvent instead of MouseEventtwo packages have the name; the Ring name gets the name of the package partlook in libraries/javalib/generated/<package>.ring, or use jNew("java.awt.event.MouseEvent",[...])
Calling Function without definition: ... for a method that exists in Javathe name is a Ring keyword (get, put, next, end, step, to, in, new, load, call ...)write the method with @: oList.@get(0), oResultSet.@next() (Rules and limits)

Calls and values#

Message or symptomCauseWhat to do
Error (R19) : Calling function with less number of parameters on a call like oSb.append()Ring needs every parameter; this method has no form without parametersgive the value, or the values as a list when the method has several overloads
Error (R20) : Calling function with extra number of parameters on a call like oField.getText(NULL) or oRandom.nextInt(1000)the method has a form without parameters, so the plain name takes no value; the forms with values are @name(x)oField.getText() and oRandom.@nextInt(1000); a method with overloads takes the values as one list: oServer.createContext(["/",oHandler])
Error (R21) : Using operator with values of incorrect type or Error (R41) : Invalid numeric string on +Ring adds when the left side is a number and joins when it is a textstring(n) first, or start the sum with a text: "" + n + " items"
a Java String is a Ring text, but x.length() fails on itstrings and numbers that come back from Java are Ring values, not objectsuse len(x); wrap with jNew("java.lang.String",[x]) when the Java method is needed
a list element or attribute stays "" after a calla Java null is an empty textjIsNull(x) tells a null object from an empty text; jNull() makes one
Java Exception: java.lang.NoSuchMethodException or a wrong overload runsthe numbers were converted to another type than the overload wantsjInt, jLong, jFloat, jDouble, jChar, jBool choose the type

Callbacks, threads and windows#

Message or symptomCauseWhat to do
a listener, a timer or a handler never runsJava calls Ring only when the Ring program runs the callbacksa window program ends with jMainLoop(); any other program waits with jPump(ms), jSleep(ms), jWaitUntil("function",ms) or jJoin(oThread)
the handler of a server or a window stops working after the function that made it returnedthe jCallback object was dropped by Ring and Java lost the functionkeep it in a variable that lives as long as the Java object (a global or an attribute)
Ring callback error: ...the Ring function of a callback raised an errorthe text after it is the Ring error with its line; fix that function
Java Error: no answer ... in 30 seconds or a timeout in a callbackthe Ring thread was busy or blocked while Java waited for itdo not block the Ring program (send() of an HTTP client blocks; use sendAsync and jWaitUntil, or jHttpGet); jCallbackTimeout(ms) changes the wait
the window closes at once, or the program endsnothing keeps the program alivejMainLoop() after setVisible(true)
a Swing program prints HeadlessExceptionthere is no display (a server, SSH, a container)give a display (xvfb-run), or test without windows: see Testing
the first window is slow to appearthe JVM starts at the first Java calljStart() early, in a program that has other work to do first

Maven, databases and the web#

Message or symptomCauseWhat to do
jMaven fails to downloadno network, or a proxythe jars of the packages are cached in ~/.ringjava/maven: copy the folder to a machine that is offline; jMaven uses the cache first
No JDBC driver accepts the URL ...the jar of the driver is not on the class pathjMaven("com.h2database:h2:2.2.224") or jClasspath("driver.jar") before jSqlConnect
Syntax error ... expected "identifier" on a create table of JavaDatabasea column has a reserved word of SQL as its name (Year, Day, Order, Group, User)rename the column (Published, Spent, Position)
Error (R31) : Trying to destroy the object using the self reference when you make an objecta global variable has the name of an attribute of the class (oDb = new MyClass with an attribute oDb)give the attributes of your classes a prefix (db_oConn), as the classes of RingJava do
a function that follows a class in a file is not foundin Ring, a function after a class is a method of that classwrite the plain functions before the first class of the file
the same text, different case: "Abc" = "abc" is false= compares texts exactlylower(a) = lower(b); use strcmp(a,b) to order texts

Still stuck?#

  1. Run the tests: powershell samples/UsingJava/tests/run.ps1 or sh samples/UsingJava/tests/run.sh (Testing). A test that fails shows what the installation cannot do.
  2. Make the program smaller until the error stays; most problems are one line.
  3. jDescribe("java.util.ArrayList") lists the members of a class, and jLastException() gives the last Java exception as an object (its printStackTrace()).
  4. Open an issue with the program, the message and the output of jInfo() and jVersion(): <https://github.com/ringpackages/ringjava/issues>
RingJava - use Java classes and methods from Ring programs.