I'm trying to run Processing from Eclipse but whenever I run the application as a Java Application I get java.lang.ClassNotFoundException.
Here's my full code:
import processing.core.PApplet;
public class App 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", "App" });
}
}
Exception:
java.lang.ClassNotFoundException: App
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
at processing.core.PApplet.main(PApplet.java:6522)
at com.WordClouds.App.main(App.java:17)
I had the same problem with the class name correctly set and also the package. This solved my issue:
PApplet.main(new String[] { "--present", MyProcessingSketch.class.getName() });
You are probably doing this tuturial : http://www.learningprocessing.com/tutorials/processing-in-eclipse/
You probably overlooked this :
public static void main(String args[]) {
PApplet.main(new String[] { "--present", "MyProcessingSketch" });
}
Note that the String “MyProcessingSketch” must match the name of your class (and if it is in a package, should include the package, i.e. packagename.MyProcessingSketch).
Related
I am trying to render a sketch with IntelliJ however when I select the P3D renderer mode, the program throws an error. I assume it has something to do with OpenGL, but I cant find anything about it online. Code is below.
import processing.core.PApplet;
public class GUI extends PApplet {
public GUI() {
}
public void settings() {
System.setProperty("jogl.disable.openglcore", "false");
fullScreen(P3D);
}
public void draw() {
background(0);
ellipse(mouseX, mouseY, 20, 20);
}
public static void main(String... args) {
PApplet.main("GUI");
}
}
The error is
java.lang.NoClassDefFoundError: com/jogamp/opengl/GLException
at processing.opengl.PGraphicsOpenGL.createPGL(PGraphicsOpenGL.java:717)
at processing.opengl.PGraphicsOpenGL.<init>(PGraphicsOpenGL.java:569)
at processing.opengl.PGraphics3D.<init>(PGraphics3D.java:35)
at java.base/jdk.internal.reflect.DirectConstructorHandleAccessor.newInstance(DirectConstructorHandleAccessor.java:67)
at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:483)
at processing.core.PApplet.makeGraphics(PApplet.java:1932)
at processing.core.PApplet.createPrimaryGraphics(PApplet.java:2011)
at processing.core.PApplet.initSurface(PApplet.java:10260)
at processing.core.PApplet.runSketch(PApplet.java:10221)
at processing.core.PApplet.main(PApplet.java:9997)
at processing.core.PApplet.main(PApplet.java:9979)
at GUI.main(GUI.java:20)
Caused by: java.lang.ClassNotFoundException: com.jogamp.opengl.GLException
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)
... 13 more
java.lang.RuntimeException: com/jogamp/opengl/GLException
at processing.core.PApplet.makeGraphics(PApplet.java:1965)
at processing.core.PApplet.createPrimaryGraphics(PApplet.java:2011)
at processing.core.PApplet.initSurface(PApplet.java:10260)
at processing.core.PApplet.runSketch(PApplet.java:10221)
at processing.core.PApplet.main(PApplet.java:9997)
at processing.core.PApplet.main(PApplet.java:9979)
at GUI.main(GUI.java:20)
Process finished with exit code 1
Thanks - any help is appreciated!
While creating a hello world program I got this exception. Here is the code:
import io.reactivex.Observable;
import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;
/**
* Created by veneet on 30/04/17.
*/
public class MainApp {
public static void main(String[] args) {
// This is where the exception occurs.
Observable<String> observable = Observable.create(e -> {
e.onNext("Hello World!");
e.onNext("Hello World!");
e.onNext("Hello World!");
e.onNext("Hello World!");
e.onNext("Hello World!");
e.onNext("Hello World!");
e.onComplete();
});
Observer<String> observer = new Observer<String>() {
#Override
public void onSubscribe(Disposable d) {
}
#Override
public void onNext(String s) {
System.out.println(s);
}
#Override
public void onError(Throwable e) {
System.err.println(e.getMessage());
}
#Override
public void onComplete() {
}
};
observable.subscribeOn(Schedulers.io());
observable.subscribe(observer);
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
The build.gradle dependencies are like this:
dependencies {
compile "io.reactivex.rxjava2:rxjava:2.1.0"
// https://mvnrepository.com/artifact/org.reactivestreams/reactive-streams
compile group: 'org.reactivestreams', name: 'reactive-streams', version: '1.0.0.final'
testCompile group: 'junit', name: 'junit', version: '4.12'
}
The complete stacktrace is like this(I think the first line is totally unrelated, but putting it to ensure):
objc[3423]: Class JavaLaunchHelper is implemented in both /Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/bin/java (0x10b6dc4c0) and /Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib/libinstrument.dylib (0x10d0194e0). One of the two will be used. Which one is undefined.
Exception in thread "main" java.lang.NoClassDefFoundError: org/reactivestreams/Publisher
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at MainApp.main(MainApp.java:11)
Caused by: java.lang.ClassNotFoundException: org.reactivestreams.Publisher
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 13 more
From the comments:
you don't have to include a dependency on Reactive-Streams because RxJava has a compile-time dependency on it already. Otherwise, the right version is:
compile 'org.reactivestreams:reactive-streams:1.0.0'
and for the Test Compatibility Kit:
testCompile 'org.reactivestreams:reactive-streams-tck:1.0.0'
The .final was a release mistake I guess.
So I was making a very basic program in java and this happened:
Exception in thread "main" java.lang.ClassNotFoundException: Main
at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:259)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:116)
Here is my "program"
public class GUI{
private JTextArea usernameInput;
private JTextArea licenceKeyOutput;
private JButton generateLicenceKeyButton;
private JPanel root;
private JPanel mainGUI;
public static void main(String[] args) {
JFrame frame = new JFrame("GUI");
frame.setContentPane(new GUI().mainGUI);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
}
public GUI() {
generateLicenceKeyButton.addActionListener(new ActionListener() {
#Override
public void actionPerformed(ActionEvent e) {
if(usernameInput.getText() == ""){
System.err.println("[IntelliGen] Invalid username received, telling user");
usernameInput.setText("Invalid Username");
licenceKeyOutput.setText("Invalid Username");
}else{
}
}
});
}
NOTE: I made this program with IntelliJ Idea's GUI Creator.
It seems that the JDK is corrupted, but it works fine with other programs. Can you guys help me in any way?
In your IntelliJ's launcher configuration Main class is set to Main which is invalid, in this case your Main class is GUI
Run > Edit Configuration > Main class:
Exception in thread "main" java.lang.ClassNotFoundException: Main
This means you are trying to run a class named main, but your class is named GUI
I am new to FreeTTS and this is my first program.The following program simply reads out a string passed.
I am using Linux Mint 32-bit if that matters.But I extracted jsapi.jar on my windows machine a day back.I believe it doesn't matter.
import javax.speech.*;
import java.util.*;
import javax.speech.synthesis.*;
public class Speak
{
String speaktext;
public void dospeak(String speak,String voicename)
{
speaktext=speak;
String voiceName =voicename;
try
{
SynthesizerModeDesc desc = new SynthesizerModeDesc(null,"general", Locale.US,null,null);
Synthesizer synthesizer = Central.createSynthesizer(desc);
synthesizer.allocate();
synthesizer.resume();
desc = (SynthesizerModeDesc) synthesizer.getEngineModeDesc();
Voice[] voices = desc.getVoices();
Voice voice = null;
for (int i = 0; i < voices.length; i++)
{
if (voices[i].getName().equals(voiceName))
{
voice = voices[i];
break;
}
}
synthesizer.getSynthesizerProperties().setVoice(voice);
System.out.print("Speaking : "+speaktext);
synthesizer.speakPlainText(speaktext, null);
synthesizer.waitEngineState(Synthesizer.QUEUE_EMPTY);
synthesizer.deallocate();
}
catch (Exception e)
{
String message = " missing speech.properties in " + System.getProperty("user.home") + "\n";
System.out.println(""+e);
System.out.println(message);
}
}
public static void main(String[] args)
{
Speak obj=new Speak();
obj.dospeak("Finally It speaks and speaks and speaks","kevin16");
}
}
I am getting this as a gift.
Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/speech/freetts/ValidationException
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:190)
at javax.speech.Central.registerEngineCentral(Central.java:703)
at javax.speech.Central.loadProps(Central.java:775)
at javax.speech.Central.availableSynthesizers(Central.java:651)
at javax.speech.Central.createSynthesizer(Central.java:553)
at Speak.dospeak(Speak.java:16)
at Speak.main(Speak.java:47)
Caused by: java.lang.ClassNotFoundException: com.sun.speech.freetts.ValidationException
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 8 more
What can I do not to accept this gift.
PS
I have added all the 4 archives viz en_us.jar,freetts-jsapi10.jar, jsapi.jar,mbrola.jar
1) Find in which jar this class is usually defined:
com.sun.speech.freetts.ValidationException
2) See if you have the jar
3) See if you have the right version of this jar
(open it, see if the class file is there)
4) See if the jar is in the classpath at runtime
My Java is very rusty and I'm having a bit of a headache here.
Here's my server.java:
import java.io.IOException;
import net.tootallnate.websocket.WebSocket;
import net.tootallnate.websocket.WebSocketServer;
public class server extends WebSocketServer
{
public server(int port)
{
super(port, Draft.AUTO);
}
public void onClientOpen(WebSocket conn)
{
System.out.println("onopen");
/*try
{
this.sendToAll(conn+" entered the room!");
}
catch(IOException ex)
{
ex.printStackTrace();
}*/
}
public void onClientClose(WebSocket conn)
{
System.out.println("onclose");
}
public void onClientMessage(WebSocket conn,String message)
{
System.out.println("onmessage"+message);
}
public static void main(String[] args)
{
int port = 8000;
try
{
port=Integer.parseInt(args[0]);
}
catch(Exception ex)
{
}
server s = new server(port);
s.start();
System.out.println("ChatServer started on port: "+s.getPort());
}
}
I need to include a jar file: ./Java-WebSocket/dist/WebSocket.jar (available from http://github.com/TooTallNate/Java-WebSocket/)
It compiles OK:
prompt> javac -classpath ./Java-WebSocket/dist/WebSocket.jar server.java
However, when I go to run:
prompt> java -classpath ./Java-WebSocket/dist/WebSocket.jar server
Exception in thread "main" java.lang.NoClassDefFoundError: server
Caused by: java.lang.ClassNotFoundException: server
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
Could not find the main class: server. Program will exit.
I hope someone can help.
Thanks in advance,
java -classpath .:./Java-WebSocket/dist/WebSocket.jar server
^^
Or on Windows:
java -classpath .;./Java-WebSocket/dist/WebSocket.jar server
^^
The classpath defaults to the current directory. You need to point to your classes as well as the library.
Isn't server placed into a package ? If it is, specify the full class name.
e.g. prompt> java -classpath ./Java-WebSocket/dist/WebSocket.jar app.core.server
I would also uppercase the class name, though.
Have you tried using the full class name (your.package.server)?