passischoppi
passischoppi

Reputation: 65

Why is there a error while importing processing-core to java?

I'm pretty new to java development. I used to program in the Processing3 IDE but now I am trying to switch to IntelliJ IDEA. All tutorials (https://www.youtube.com/watch?v=_h2GZgnPcnM) import it so I am trying to import processing.core.PApplet too. I also added the core.jar to the Libraries at the Project Structure Settings.

When I import the core but don't extend it (whatever this means) to the Main class I don't get any errors. After extending it to Main class I get the error.

import processing.core.PApplet;

public class Main extends PApplet{
    public static void main(String[] args) {
        //PApplet.main("Main");
    }
}

I expect it to run properly because I followed the instructions given in the tutorial. The error message is:

Exception in thread "main" java.lang.ExceptionInInitializerError
Caused by: java.lang.ArrayIndexOutOfBoundsException: Index 1 out of bounds for length 1
    at processing.core.PApplet.<clinit>(PApplet.java:122)

I hope you can tell me what the error message means...

Thanks

Upvotes: 3

Views: 1873

Answers (1)

vs97
vs97

Reputation: 5859

This problem has been recorded in this GitHub issue. Such error message was present when Processing 3.3.6 (x64) was launched with JDK 9 (x64) - the decompling bytecode leads to the error with this code:

javaPlatform = parseInt(split(javaVersionName, '.')[1]);

But it seems that JDK 9 version was being returned as just "9" but not "9.0".


String ver = System.getProperty("java.version");
System.out.println(ver);

returns just "9". The code in PApplet.java tries to split it using "." and take [ 1 ] element that does not exist. This causes the error that you are seeing.

I was not able to replicate your issue on Windows 10, Processing 3.5.3 and with using Java 10, therefore I assume that your problem has been fixed in more recent versions of Java. From the video you posted in your question, it appears that the video author is using Java 8 for Processing 3.3.6 - make sure you have the same setup. Else, use a more recent JDK (e.g. Java 10) if you are using the latest Processing version (3.5.3).

Upvotes: 2

Related Questions