0

I'm trying to get a simple example to run. The below code compiles but gives me errors when I try to run it. I'm a newbie to Processing/Java. Also, my goal is to see if I can make a simple command line utility with processing for charting/graphics (very simple), kind of like gnuplot.

import processing.core.*;

public class MyProcessingSketch extends PApplet {

  public void setup() {
    size(200,200);
    background(0);
  }

  public void draw() {
    stroke(255);
    if (mousePressed) {
      line(mouseX,mouseY,pmouseX,pmouseY);
    }
  }
  public static void main(String args[]) {
    PApplet.main(new String[] { "--present", "MyProcessingSketch" });
  }
}

I build with

javac -cp location/of/core/core.jar MyProcessingSketch.java

and run with

java -cp location/of/core/core.jar MyProcessingSketch

the error I get is,

Exception in thread "main" java.lang.NoClassDefFoundError: MyProcessingSketch

EDIT:

I've now tried

java -cp "location/of/core/core.jar:." MyProcessingSketch

and the error is now,

Exception in thread "main" java.lang.RuntimeException: java.lang.NullPointerException
4
  • 1
    You're trying to run an applet as a desktop application. At best it should be loaded into a browser, at worse, you can try using the applet viewer included with the JDK Commented Apr 30, 2013 at 0:19
  • "I'm a newbie to Processing..." Why are you bothering with that primitive AWT based API? Commented Apr 30, 2013 at 1:20
  • As an aside, what is the --present attribute? I don't see it mentioned in the JavaDocs. Commented Apr 30, 2013 at 2:51
  • It was part of a simple example that works with eclipse. Commented Apr 30, 2013 at 20:29

2 Answers 2

4

You have set your classpath to location/of/core/core.jar, but that doesn't include the current directory where your class lies.

Include "." (the current directory) in your classpath option:

java -cp "location/of/core/core.jar:." MyProcessingSketch

The ":" is the path separator on Unix and Linux; use a semicolon on Windows instead.

java -cp "location/of/core/core.jar;." MyProcessingSketch
Sign up to request clarification or add additional context in comments.

1 Comment

@ctsa It is also a good idea to put your class in a package. Then you would run mypackage.MyProcessingSketch
0

Your classpath currently only contains location/of/core/core.jar, and not MyProcessingSketch.class. You should do java -cp location/of/core/core.jar;. MyProcessingSketch to include the current directory.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.