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 symptom | Cause | What to do |
|---|---|---|
Error (E9) : Can't open file java.ring | the package is not installed in the Ring that runs the program | extract 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.so | no JDK was found | give 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 bridge | ringjava.jar is not next to the extension | the 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 file | the loader does not know where Ring is | export 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 jar | it is copied with the jar by setup.ring and by the build scripts |
Classes and packages#
| Message or symptom | Cause | What to do |
|---|---|---|
Error (R11) : Error in class name, class not found: arraylist | the package is not imported | using { "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 package | a 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 meanings | import 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 MouseEvent | two packages have the name; the Ring name gets the name of the package part | look in libraries/javalib/generated/<package>.ring, or use jNew("java.awt.event.MouseEvent",[...]) |
Calling Function without definition: ... for a method that exists in Java | the 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 symptom | Cause | What 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 parameters | give 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 text | string(n) first, or start the sum with a text: "" + n + " items" |
a Java String is a Ring text, but x.length() fails on it | strings and numbers that come back from Java are Ring values, not objects | use len(x); wrap with jNew("java.lang.String",[x]) when the Java method is needed |
a list element or attribute stays "" after a call | a Java null is an empty text | jIsNull(x) tells a null object from an empty text; jNull() makes one |
Java Exception: java.lang.NoSuchMethodException or a wrong overload runs | the numbers were converted to another type than the overload wants | jInt, jLong, jFloat, jDouble, jChar, jBool choose the type |
Callbacks, threads and windows#
| Message or symptom | Cause | What to do |
|---|---|---|
| a listener, a timer or a handler never runs | Java calls Ring only when the Ring program runs the callbacks | a 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 returned | the jCallback object was dropped by Ring and Java lost the function | keep 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 error | the 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 callback | the Ring thread was busy or blocked while Java waited for it | do 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 ends | nothing keeps the program alive | jMainLoop() after setVisible(true) |
a Swing program prints HeadlessException | there 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 appear | the JVM starts at the first Java call | jStart() early, in a program that has other work to do first |
Maven, databases and the web#
| Message or symptom | Cause | What to do |
|---|---|---|
jMaven fails to download | no network, or a proxy | the 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 path | jMaven("com.h2database:h2:2.2.224") or jClasspath("driver.jar") before jSqlConnect |
Syntax error ... expected "identifier" on a create table of JavaDatabase | a 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 object | a 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 found | in Ring, a function after a class is a method of that class | write the plain functions before the first class of the file |
the same text, different case: "Abc" = "abc" is false | = compares texts exactly | lower(a) = lower(b); use strcmp(a,b) to order texts |
Still stuck?#
- Run the tests:
powershell samples/UsingJava/tests/run.ps1orsh samples/UsingJava/tests/run.sh(Testing). A test that fails shows what the installation cannot do. - Make the program smaller until the error stays; most problems are one line.
jDescribe("java.util.ArrayList")lists the members of a class, andjLastException()gives the last Java exception as an object (itsprintStackTrace()).- Open an issue with the program, the message and the output of
jInfo()andjVersion(): <https://github.com/ringpackages/ringjava/issues>