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:
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!
I am writting a library to ease the development of JavaFX application, and in order to make it usable with Java modular system, I need to get the URL of the FXML file in another java module (the client module) and pass it to FXMLLoader in my library (the library module).
So to sum:
I need to get the resource URL of an FXML file in the client module to be read in the library module.
I tried:
Accessing resource files from external modules
Load a Resource from another Module in Java (With Maven)
My latest attempt:
private void addController(ControllerInfo info, Class<? extends SimpleController> controllerClass) throws IOException {
String filename = info.FXMLFile();
if (!filename.startsWith("/"))
filename = "/" + filename;
ModuleReference ref=ModuleLayer.boot().configuration().findModule(moduleName).map(ResolvedModule::reference).get();
ModuleReader resReader=ref.open();
URL url = resReader.find(filename).get().toURL();
controllerClasses.put(info.Id(), controllerClass);
info.Type().getAction().addController(info, url, controllerClass);
}
In the client module I have placed my resources inside a io/github/ossnass/languageexample folder in the resources folder, and the module-info.java looks like this:
module languageExample {
requires javafx.controls;
requires javafx.fxml;
requires simplefx;
opens io.github.ossnass.languageexample.gui to javafx.fxml;
opens io.github.ossnass.languageexample to simplefx;
exports io.github.ossnass.languageexample.app;
}
The FXML contoller class:
#ControllerInfo(Id = "LangMain", FXMLFile = "/io/github/ossnass/languageexample/langexample.fxml", Type = ContollerType.SINGLE_INSTANCE_ON_STARTUP)
public class LangExampleMain extends SimpleController {
#Override
protected void userInit() {
}
#Override
protected void onStageShowUser() {
}
#FXML
private Button btnMessage;
#FXML
void btnMessageClick(ActionEvent event) {
QuickActions.showInfoMessage(null,
resources.getString("InfoHeader"),
resources.getString("InfoBody"),
this);
}
}
I get the following error:
java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:464)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:363)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:1051)
Caused by: java.lang.RuntimeException: Exception in Application start method
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:900)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:195)
at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.util.NoSuchElementException: No value present
at java.base/java.util.Optional.get(Optional.java:148)
at io.github.ossnass.fx.ControlMaster.addController(ControlMaster.java:179)
at io.github.ossnass.fx.ControlMaster.findControllers(ControlMaster.java:198)
at io.github.ossnass.fx.ControlMaster.initControlMaster(ControlMaster.java:134)
at io.github.ossnass.languageexample.app.Main.start(Main.java:11)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:846)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:455)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
at javafx.graphics/com.sun.glass.ui.gtk.GtkApplication._runLoop(Native Method)
at javafx.graphics/com.sun.glass.ui.gtk.GtkApplication.lambda$runLoop$11(GtkApplication.java:277)
... 1 more
The URL path to the resource file is :/io/github/ossnass/languageexample/langexample.fxml
Please notice that I am using Maven and I put the FXMLs in the resources dir.
The library I am developing can be found at SimpleFX
I was able to solve the problem using ClassGraph library with some help of how to properly make the URL from VGR
The following bit of code solved all (Java 8 and Java 9+ with modular system):
public static Resource getRescoure(String urlStr) {
try (ScanResult scan = new ClassGraph().scan()) {
if (urlStr.startsWith("/"))
urlStr = urlStr.substring(1);
ResourceList rl = scan.getResourcesWithPath(urlStr);
if (rl.size() > 0)
return rl.get(0);
return null;
}
}
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.
My Main
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class MainApp {
public static void main(String[] args) {
System.out.println("hola");
ApplicationContext context = new ClassPathXmlApplicationContext("Beans.xml");
HelloWorld obj = (HelloWorld) context.getBean("helloWorld");
obj.getMessage();
}
}
Exception in thread "main" java.lang.ExceptionInInitializerError
at org.springframework.context.support.AbstractRefreshableApplicationContext.createBeanFactory(AbstractRefreshableApplicationContext.java:201)
at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:127)
at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:551)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:465)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
at com.tutorialspoint.MainApp.main(MainApp.java:9)
Caused by: java.lang.NullPointerException
at org.springframework.beans.factory.support.
DefaultListableBeanFactory.<clinit>(DefaultListableBeanFactory.java:108)
... 7 more
The NullPointerException error is at almost impossible location:
static {
ClassLoader cl = DefaultListableBeanFactory.class.getClassLoader();
try {
javaxInjectProviderClass = cl.loadClass("javax.inject.Provider"); /* line 108 */
} catch (ClassNotFoundException ex) {
// JSR-330 API not available - Provider interface simply not supported then.
}
}
This means that the class is not able to get its own classloader. You must have done something really bad to get this error. Check your JRE/JDK, IDE, ...
UPDATE
There is no explanation other than that you are probably trying to put Spring JARs into JRE's library folder (${java.home}/jre/lib). If that is the case, that is simply wrong. If you really want to include external JARs within JRE, then put them in the official extension directory - ${java.home}/jre/lib/ext.
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Troubleshooting ClassNotFoundException when using PHP/Java bridge
Can anyone please explain me about the PHP/Java Bridge installation.
I already installed bridge in my system.
This is my HelloWorld.java code :
import javax.swing.JOptionPane;
public class HelloWorld
{
public static final String JAVABRIDGE_PORT="8081";
static final php.java.bridge.JavaBridgeRunner runner =
php.java.bridge.JavaBridgeRunner.getInstance(JAVABRIDGE_PORT);
public static void main(String args[]) throws Exception
{
runner.waitFor();
System.exit(0);
}
public void hello(String args[]) throws Exception
{
JOptionPane.showMessageDialog(null, "hello " + args[0]);
}
}
This is my HelloWorld.php code:
<?php
require_once("http://localhost:8081/JavaBridge/java/Java.inc");
$world = new java("HelloWorld");
echo $world->hello(array("from PHP"));
?>
While calling Java class from php, it is not working and it is showing the below error:
Fatal error: Uncaught [[o:Exception]:"java.lang.Exception: CreateInstance failed: new HelloWorld. Cause: java.lang.ClassNotFoundException: HelloWorld VM: 1.5.0_01#http://java.sun.com/" at: #-31 org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1438) #-30 org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1284) #-29 java.lang.ClassLoader.loadClassInternal(Unknown Source) #-28 java.lang.Class.forName0(Native Method) #-27 java.lang.Class.forName(Unknown Source) #-26 php.java.bridge.Util.classForName(Util.java:1518) #-25 php.java.bridge.JavaBridge.CreateObject(JavaBridge.java:445) #-24 php.java.bridge.Request.handleRequest(Request.java:458) #-23 php.java.bridge.Request.handleOneRequest(Request.java:510) #-22 php.java.servlet.PhpJavaServlet.handleLocalConnection(PhpJavaServlet.java:202) #-21 php.java.servlet.PhpJavaServlet.handlePut(PhpJavaServlet.java:250) #-20 php.java.servlet.PhpJavaServlet.doPut(PhpJavaServlet.java:261) #-19 javax.servlet.http.HttpServlet.service(HttpS in http://localhost:8081/JavaBridge/java/Java.inc on line 195
Can you please anyone help me on this.
Thanks in advance.
I am unfamiliar with the package you are trying to use but it looks like you need to give the full path to your class. That is java/lang/ClassNotFoundException for example for the Java Exception that is being thrown and probably something like me/mypackage/HelloWordl for the class you are trying to create.