I am getting an error when running java program using processing core v 3.3.7.
I tried other versions, but it didn't help.
The error I get is the following:
Exception in thread "main" java.lang.ExceptionInInitializerError
Caused by: java.lang.StringIndexOutOfBoundsException: begin 0, end -1, length 2
at java.base/java.lang.String.checkBoundsBeginEnd(String.java:3319)
at java.base/java.lang.String.substring(String.java:1874)
at processing.core.PApplet.<clinit>(PApplet.java:120)
The code is provided below:
import processing.core.PApplet;
public class ProcessingTest extends PApplet {
#Override
public void settings() {
size(200, 200);
}
#Override
public void draw() {
background(0);
fill(255, 0, 0);
ellipse(100, 100, 100, 100);
}
public static void main (String... args) {
ProcessingTest pt = new ProcessingTest();
PApplet.runSketch(new String[]{"ProcessingTest"}, pt);
}
}
I can't see what the problem is.
Strangely enough I couldn't replicate your issue.
Is your class in a package ? If so, might be worth passing the full class path including the package. e.g:
PApplet.runSketch(new String[]{ProcessingTest.class.getCanonicalName()}, pt);
you can also try:
PApplet.main(ProcessingTest.class.getCanonicalName());
Additionally, it's worth mentioning what OSX you're on and what JDK you used to compile, and what your machine outputs when calling System.getProperty("java.version");.
Having a quick skim through Processing source code I spotted this line:
javaPlatform = parseInt(version.substring(0, version.indexOf('.')));
Depending on your OS this might a basic bug parsing an unexpected string.
Related
My goal: Running Processing.org (version 3.5.4) from Max (cycling74) version 8 on Windows 10 64 through writing an MXJ external (Max Java support). I want to open a processing test sketch within window from MAX by sending a bang message to the MXJ external. For this I have
class MaxJavaTest3 extends MaxObject which calls
class TestProcessing extends PApplet.
public class MaxJavaTest3 extends MaxObject {
public void bang() {
String[] args = {};
TestProcessing.main(args);
}
}
public class TestProcessing extends PApplet {
public static void main(String args[] ) {
PApplet.main("TestProcessing", args);
}
public void settings() {
size(920, 780);
}
public void setup() {
background(0);
fill(255, 0, 0);
circle(width/2, height/2, 80);
}
}
In IntelliJ, I set the dependencies for Max and Java. The bang message is received in Java e.g. triggering some text messages to the console. If I execute PApplet.main via the entry point TestProcessing.main, the processing window opens. So far so good, but trying to invoke PApplet.main via MaxJavaTest3.bang() method I get the error:
java.lang.RuntimeException: java.lang.ClassNotFoundException: TestProcessing
at processing.core.PApplet.runSketch(PApplet.java:10852)
at processing.core.PApplet.main(PApplet.java:10657)
at TestProcessing.main(TestProcessing.java:11)
at MaxJavaTest3.bang(MaxJavaTest3.java:19)
Caused by: java.lang.ClassNotFoundException: TestProcessing
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
at processing.core.PApplet.runSketch(PApplet.java:10845)
... 3 more
```JAVA
I found a post which suggests that there is a problem with Max using ProcessingĀ“s OpenGL related capacities: "since OpenGL uses also native libraries (*.dll files) and not only *.jar files. I don't know if its possible in MaxMSP - that depends on how they set up their JVM."
https://forum.processing.org/one/topic/use-processing-from-within-max-msp-or-from-matlab.html
I'm currently working on image dynamic overlaying in java. My server will render images based on runtime parameters so I need a library to work with Images in a simple manner.
I've heard about Processing and curious about how to use it with my Spring boot server. Can I just use Processing as a Library without setup() draw() functions? Just run processing to load images, make operations on them and upload result in AWS S3 so end client will reach it?
I've tried to just use
import processing.core.PApplet;
import processing.core.PImage;
public class Application {
public static void main(String[] args) {
PApplet pApplet = new PApplet();
PImage pImage = pApplet.loadImage("/home/vadim/Pictures/lena.png");
PImage pImage2 = pApplet.loadImage("/home/vadim/Pictures/lena.png");
pImage.blend(pImage2, 0, 0, 50, 50, 0, 0, pImage2.width, pImage2.height, PImage.OVERLAY);
pImage.save("/home/vadim/Pictures/result.png");
}
}
Is it possible at all? or maybe I need to consider some another library for it?
As far as I know, you can't use Processing's functions as standalone without at least a setup() function. This is because Processing needs to do its own initialization before most of its functions work.
But note that you don't need to include a draw() function. You can do everything from setup(), something like this:
public class TestSketch extends PApplet {
public void setup() {
background(32);
ellipse(50, 50, 25, 25);
noLoop();
}
static public void main(String[] passedArgs) {
String[] appletArgs = new String[] { "TestSketch" };
PApplet.main(appletArgs);
}
}
That being said, you might be able to hack at Processing's source to isolate the functionality you want. This is probably more work than it's worth though.
Shameless self-promotion: here is a guide on using Processing as a Java library. Here is a guide on running Processing without a display.
I want to create two windows by using just one single sketch in Processing.
What I'm trying to do is that if I click a button in one window, then some image appear in another window.
I've searched Google and found some examples. Actually, I found the same question in this 'stack overflow web'. Here are the links.
Create more than one window of a single sketch in Processing
http://forum.processing.org/one/topic/multiple-windows-2-4-2011.html
Here is the codes of second links.
import java.awt.Frame;
PFrame f;
secondApplet s;
//f = new PFrame();
void setup() {
size(320, 240);
f = new PFrame();
}
void draw() {
background(255,0,0);
fill(255);
rect(10,10,frameCount%0,10);
s.background(0, 0, 255);
s.fill(100);
s.rect(10,20,frameCount%0,10);
s.redraw();
}
public class PFrame extends Frame{
public PFrame() {
setBounds(100,100,400,300);
s = new secondApplet();
add(s);
s.init();
show();
}
}
public class secondApplet extends PApplet {
public void setup() {
size(400, 300);
noLoop();
}
public void draw() {
}
}
But when I run this codes, I get the following error message at add(s);.
The method add(Component) in the type Container is not applicable for the arguments (multi_window_test.secondApplet)
Code of first comment of first link is similar, but when I run this code, I get the same error message.
Other example codes that I found are all similar. They all create PFrame class and secondApplet which extends PApplet. They said these codes works well but I can't run these codes.
I couldn't find the reason of my error message. Other people seems to have no problem when running this example code except me.
If someone knows the solution, please help me.
Also, if there is a other simple way to create multi-windows in one sketch, please let me know.
The reason for the error message is pretty self-explanatory: the add() function is expecting a Component, and PApplet is not a Component. This is because PApplet no longer extends Applet as of Processing 3, so old code that uses it as a Component will no longer work.
Instead, consider my answer to this question. Basically, just create a class that extends PApplet for your second window, and then call PApplet.runSketch() using that second PApplet as a parameter:
void setup() {
size(100, 100);
String[] args = {"TwoFrameTest"};
SecondApplet sa = new SecondApplet();
PApplet.runSketch(args, sa);
}
void draw() {
background(0);
ellipse(50, 50, 10, 10);
}
public class SecondApplet extends PApplet {
public void settings() {
size(200, 100);
}
public void draw() {
background(255);
fill(0);
ellipse(100, 50, 10, 10);
}
}
I need to call Windows Color System functions from Java. Following this tutorial i tried to call DLL function using Java Native Access. All examples from this tutorial works fine. When i try to load and use Mscms.dll (one of the WCS libraries) that DLL seems to be loaded successfully, but i can not call any functions. List of functions is here.
I got a message:
Exception in thread "main" java.lang.UnsatisfiedLinkError: Error looking up function 'GetColorDirectory'
What's wrong with my code? Could you help me please?
import com.sun.jna.Library;
import com.sun.jna.Native;
public class WCS_test {
public interface Mscms extends Library {
// http://msdn.microsoft.com/en-us/library/dd316928%28v=vs.85%29.aspx
boolean GetColorDirectory(String pMachineName, String[] pBuffer, int pdwSize);
}
private static Mscms mscms = (Mscms) Native.loadLibrary("C:/Windows/system32/Mscms.dll", Mscms.class);
public static void main(String[] args) {
if (mscms != null)
System.out.println("Library loaded\n");
else
System.err.println("Library loading error\n");
String[] pBuffer = new String[1024];
mscms.GetColorDirectory(null, pBuffer, pBuffer.length);
}
}
When you get a java.lang.UnsatisfiedLinkError that means that it could not find the function 'GetColorDirectory' inside of the Mscms.dll. Looking at the link from your source code http://msdn.microsoft.com/en-us/library/dd316928%28v=vs.85%29.aspx you should try the Unicode name GetColorDirectoryW.
I wrote this simple code:
public class Test {
public static void main(String args[]) {
OculusRift oculusRift = new OculusRift();
oculusRift.init();
HMDInfo hdmInfo = oculusRift.getHMDInfo();
System.out.println(hdmInfo);
// while(oculusRift.isInitialized()){
//
// }
oculusRift.destroy();
}
}
But I get this error
Exception in thread "main" java.lang.UnsatisfiedLinkError: de.fruitfly.ovr.OculusRift._initSubsystem()Z
at de.fruitfly.ovr.OculusRift._initSubsystem(Native Method)
at de.fruitfly.ovr.OculusRift.init(OculusRift.java:82)
at ec.test.test3.Test.main(Test.java:21)
Java Result: 1
I created and included a Library based on:
JRift-0.2.5.1.jar
JRiftLibrary-0.2.5.1.jar
JRiftLibrary-0.2.5.1-natives-windows.jar
From here
What is missing?
Edit:
Forced by extracting JRiftLibrary64.dll and adding its path explicitly to the java path
System.loadLibrary("JRiftLibrary64");
It works.. why does not work on the other way?
Have you tried JOVR? https://github.com/jherico/jovr
Here a complete example: https://github.com/jherico/jocular-examples
This library is simple, very solid and compatible with the current Oculus Runtime 1.8
Regards