How to use the P3D Renderer while using Processing in Intellij - java

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!

Related

How to make 3D in processing library

I'm using the Processing library in a simple Java project and I tried to make 3D but I got errors, this is my code :
package fr.ayfri;
import processing.core.PApplet;
import processing.core.PConstants;
public class Main extends PApplet {
public void settings() {
size(1600, 900, PConstants.P3D); // <--- P3D this tells Processing to work with 3D
}
public void draw() {
background(140, 190, 255);
}
public static void main(String[] args) {
String[] processingArgs = { "Main" };
Main main = new Main();
PApplet.runSketch(processingArgs, main);
}
}
But when I run the code I get this error :
java.lang.NoClassDefFoundError: com/jogamp/opengl/GLCapabilitiesImmutable
at processing.opengl.PGraphicsOpenGL.createPGL(PGraphicsOpenGL.java:712)
at processing.opengl.PGraphicsOpenGL.<init>(PGraphicsOpenGL.java:569)
at processing.opengl.PGraphics3D.<init>(PGraphics3D.java:35)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:481)
at processing.core.PApplet.makeGraphics(PApplet.java:2266)
at processing.core.PApplet.createPrimaryGraphics(PApplet.java:2345)
at processing.core.PApplet.initSurface(PApplet.java:10983)
at processing.core.PApplet.runSketch(PApplet.java:10922)
at fr.ayfri.Main.main(Main.java:20)
Caused by: java.lang.ClassNotFoundException: com.jogamp.opengl.GLCapabilitiesImmutable
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:602)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 13 more
java.lang.RuntimeException: com/jogamp/opengl/GLCapabilitiesImmutable
at processing.core.PApplet.makeGraphics(PApplet.java:2299)
at processing.core.PApplet.createPrimaryGraphics(PApplet.java:2345)
at processing.core.PApplet.initSurface(PApplet.java:10983)
at processing.core.PApplet.runSketch(PApplet.java:10922)
at fr.ayfri.Main.main(Main.java:20)
Process finished with exit code 1
So I just don't know how to make this works ?
P3D uses OpenGL behind the scenes and you need to link against the native libraries.
In this case it's the jogl and gluegen-rt libraries present in Processing/Java/core/libraries: simply copy the correct jars for your platform (or all if you want to run the project on multiple platforms) and add them to the build path.
Here's an eclipse OSX example:

java.lang.NoClassDefFoundError: com/google/common/cache/RemovalListener

I want to work telegram API, I create Bot in telegram and set username and get a token but I can not connect with my java code please help me
I use this code
ApiContextInitializer.init();
TelegramBotsApi telegramBotsApi = new TelegramBotsApi();
try {
telegramBotsApi.registerBot(new TradeBot());
} catch (TelegramApiException e) {
e.printStackTrace();
}
and my proxy is set and test connection is right
public class TradeBot extends TelegramLongPollingBot {
public void onUpdateReceived(Update update) {
}
public String getBotUsername() {
return "xxx";
}
public String getBotToken() {
return "xxx";
}
}
and after run code give this error :
Exception in thread "main" java.lang.NoClassDefFoundError: com/google/common/cache/RemovalListener
at com.google.inject.internal.InheritingState.<init>(InheritingState.java:63)
at com.google.inject.internal.InjectorShell$Builder.getState(InjectorShell.java:208)
at com.google.inject.internal.InjectorShell$Builder.lock(InjectorShell.java:114)
at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:102)
at com.google.inject.Guice.createInjector(Guice.java:87)
at com.google.inject.Guice.createInjector(Guice.java:69)
at com.google.inject.Guice.createInjector(Guice.java:59)
at org.telegram.telegrambots.meta.ApiContext.getInjector(ApiContext.java:48)
at org.telegram.telegrambots.meta.ApiContext.getInstance(ApiContext.java:27)
at org.telegram.telegrambots.bots.TelegramLongPollingBot.<init>(TelegramLongPollingBot.java:16)
at TradeBot.<init>(TradeBot.java:6)
at MainClass.main(MainClass.java:10)
Caused by: java.lang.ClassNotFoundException: com.google.common.cache.RemovalListener
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:602)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 12 more
Was answered here:
Google Guice can't find class
You need the correct version of the com.google.guava/guava dependency related to the com.google.inject/guice library that you are already using.

Running Slick2D results in NoClassDefFoundError

I have tried to run a simple game using Java and keep getting an error when I try to run this application.
Exception in thread "main" java.lang.NoClassDefFoundError: sun/misc/Unsafe ...
I think my problem is that my JDK (12.0.2) does not support these Slick2D as it is "OutDated". If downgrading my Java Version is a solution can someone please explain how I can find a version of Java that supports Slick2D?
I have already set up my libraries in my IDE and set my path. I tried to run the same application in the newest Intellij and eclipse environments. I currently have JDK 12.0.2 installed and a 2015 version of LWJGL plus Slick2D installed.
package classPackage;
import org.newdawn.slick.*;
public class Game extends BasicGame{
public Game(String gamename) {
super(gamename);
}
#Override
public void init(GameContainer gc) throws SlickException {
}
#Override
public void update(GameContainer gc, int i) throws SlickException {
}
#Override
public void render(GameContainer gc, Graphics g) throws SlickException {
g.drawString("Howdy!", 10, 10);
}
public static void main(String[] args) {
try {
AppGameContainer appgc;
appgc = new AppGameContainer(new Game("Simple Slick Game"));
appgc.setDisplayMode(640, 480, false);
appgc.start();
} catch (SlickException ex) {
}
}
}
Error:
Exception in thread "main" java.lang.NoClassDefFoundError: sun/misc/Unsafe
at lwjgl/org.lwjgl.MemoryUtilSun$AccessorUnsafe.getUnsafeInstance(MemoryUtilSun.java:74)
at lwjgl/org.lwjgl.MemoryUtilSun$AccessorUnsafe.<init>(MemoryUtilSun.java:62)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500)
at java.base/java.lang.reflect.ReflectAccess.newInstance(ReflectAccess.java:166)
at java.base/jdk.internal.reflect.ReflectionFactory.newInstance(ReflectionFactory.java:404)
at java.base/java.lang.Class.newInstance(Class.java:590)
at lwjgl/org.lwjgl.MemoryUtil.loadAccessor(MemoryUtil.java:375)
at lwjgl/org.lwjgl.MemoryUtil.<clinit>(MemoryUtil.java:63)
at lwjgl/org.lwjgl.opengl.WindowsDisplay.setTitle(WindowsDisplay.java:522)
at lwjgl/org.lwjgl.opengl.Display.setTitle(Display.java:541)
at lwjgl/org.lwjgl.opengl.Display.createWindow(Display.java:312)
at lwjgl/org.lwjgl.opengl.Display.create(Display.java:848)
at lwjgl/org.lwjgl.opengl.Display.create(Display.java:757)
at slick/org.newdawn.slick.AppGameContainer.tryCreateDisplay(AppGameContainer.java:302)
at slick/org.newdawn.slick.AppGameContainer.access$000(AppGameContainer.java:34)
at slick/org.newdawn.slick.AppGameContainer$2.run(AppGameContainer.java:353)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:310)
at slick/org.newdawn.slick.AppGameContainer.setup(AppGameContainer.java:348)
at slick/org.newdawn.slick.AppGameContainer.start(AppGameContainer.java:317)
at testGame/classPackage.Game.main(Game.java:31)
Caused by: java.lang.ClassNotFoundException: sun.misc.Unsafe
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 23 more
I was able to get this issue resolved by downgrading my jdk to 8. Thank you all I hope this will help someone in the future.

Error with a main method

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

ClassNotFoundException when accessing Processing from Eclipse

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).

Categories

Resources