OpenGL in Java on Netbeans: NoClassDefFoundError - java

I am on a Mac running Netbeans 6.9.
I downloaded and installed LWJGL using this tutorial down to the letter:
http://lwjgl.org/wiki/index.php?title=Setting_Up_LWJGL_with_NetBeans
I finished the installation and copied sample code to see if my system is working. I got a bug, and was not sure if it was because of faulty code or I was doing something wrong. So I shortened down the code to this little simple bit:
package javaopengl;
import org.lwjgl.Sys;
import org.lwjgl.opengl.Display;
//Testing
public class Main {
public static void main(String[] args) {
boolean fullscreen = (args.length == 1 && args[0].equals("-fullscreen"));
try {
Display.create();
Display.destroy();
} catch (Exception e) {
e.printStackTrace(System.err);
}
System.exit(0);
}
}
But I still get the same error:
run:
Exception in thread "main" java.lang.NoClassDefFoundError: =
Caused by: java.lang.ClassNotFoundException: =
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:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)
I am not sure what exactly is going on, Would you please tell me what is going on and how to fix it?
Note: When i am looking at the text in the development environment, it does not show those red lines indicating there are any errors.

What are you typing (or what is netbeans running) to run this? Since the Mac filesystem is fairly case-agnostic unless you've specified otherwise, running java javaopengl.main will look for a file main.java, which is there (Main.java will be returned). But the class is Main, and you can get this exception from the difference. If this is being run from an ant script, I suggest making sure you have the correct capitalization (the class should be javaopengl.Main). A simple way to test this is to delete everything except the class definition and an empty public static void main(String[] args) {}
Alternatively, you could have something simpler, like your classpath out of whack. Missing the lwjgl jar would get you there, but if you followed the directions in that tutorial, that actually seems less likely. Still, you can test this.
package javaopengl;
public class Main {
public static void main(String[] args) {
System.out.println("well, main works");
Class checkjar = Class.forName("org.lwjgl.opengl.Display");
System.out.println("My ClassLoader found: " + checkjar.getCanonicalName());
}
}
Also, remove import org.lwjgl.Sys; from your shortened example. It doesn't appear to be needed, provided it isn't the source of your problems :).

Related

How to get Lightrun running in IntelliJ IDEA 2022.3.1?

No matter what I do Lightrun will generate the following error message:
General agent error at jvm_internals.cc:186.
This is my first time using Lightrun.
This is my code:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
System.out.println(new Scanner(System.in).nextInt() + new Scanner(System.in).nextInt());
}
}
The code itself runs perfectly.
I am using IntelliJ IDEA 2022.3.1.
LR doesn’t work on this version. A bit buggy on the ij versions for the past 2 months…

"Error: Could not find or load main class ..."

import java.util.Scanner;
import java.io.*;
import java.io.FileNotFoundException;
public class bookreader {
public static void main(String[] args) throws FileNotFoundException {
//...
}
}
When I run this code normally it spits out:
Exception in thread "main" java.lang.ClassNotFoundException: bookreader
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)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:122)
When I debug the code it spits out:
Error: Could not find or load main class bookreader
I'm pretty sure both errors are the same, but I don't know how to fix either of them. Other answer point towards it running as a wrong file type, but the name of the file is bookreader.java which should run it in Java like needed in Intellij.
Try the down-to-up method: Code a simple "Hello world" class, with no packages and no imports, and run it from the IDE. If it compiles well but does not run, either the project is not OK, or either the IDE is not OK.
Instead, if it runs, add more logic to this dummy class to make it resemble your initial class, repeating the test after every edit. When it fails, you'll know what was the last edit.
Make sure you are calling the class/Running the program like this :
"java bookreader" and NOT like "java bookreader.class"

Setting up LWJGL with Eclipse Mac Error

I have been following this link in order to set up the workspace, named "towerpg" (I wanted to create an RPG game in Java): https://www.youtube.com/watch?v=0v56I5UWrYY&feature=iv&src_vid=VS8wlS9hF8E&annotation_id=annotation_3428321851
I've followed every single step on the YouTube Video, however, I'm getting this error:
Exception in thread "main" java.lang.UnsatisfiedLinkError: no lwjgl in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1764)
at java.lang.Runtime.loadLibrary0(Runtime.java:823)
at java.lang.System.loadLibrary(System.java:1044)
at org.lwjgl.Sys$1.run(Sys.java:72)
at java.security.AccessController.doPrivileged(Native Method)
at org.lwjgl.Sys.doLoadLibrary(Sys.java:66)
at org.lwjgl.Sys.loadLibrary(Sys.java:96)
at org.lwjgl.Sys.<clinit>(Sys.java:117)
at org.lwjgl.opengl.Display.<clinit>(Display.java:135)
at towerpg.Main.main(Main.java:11)
My code:
package towerpg;
import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.Display;
public class Main {
public static void main(String[] args) {
try {
Display.create();
} catch (LWJGLException e) {
e.printStackTrace();
}
}
}
Not sure what I did wrong here, I've done everything I'm supposed to do. Is someone able to help me?
Add a JVM option that says:
-Djava.library.path="/path/to/mac/native/files/directory"
The directory should be in the downloaded LWJGL files.

When running Eclipse, I am getting a error in console after running the code

So am literally taking a intro to Java Programming and now I am trying to create my second assignment. Upon doing so I have created the new java class within eclipse, but when I try to run the code that I have written, I am getting the following errors.
I am not real sure on how to fix this. Any assistance would be greatly appreciated.
Exception in thread "main" java.lang.NoClassDefFoundError: math
Caused by: java.lang.ClassNotFoundException: math
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:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
ClassNotFoundException: math
I'm guessing you created a class with a capital M in math, but when you call it somewhere, it's not capitalized, or referenced properly. Try to double check that in your code.
Friendly FYI for proper Java standards, try to make sure that classes are capitalized.
You said your code is the following:
public class rounding {
public static void main (string[] args){
System.outprintln("Hello World");
From the error message you received, you most likely have this code in a file named math.java. In Java, you must declare the class name as equal to the file name; for example, YourClass.java would declare public class YourClass {.
So what you need to do is either rename your class name to math, or name your file rounding.java, although it is unconventional to begin class names with a lower case letter.
On top of these errors however, you'll run into an error saying that the type string does not exist. You need to rename that the type string[] to String[] or the JVM won't be able to identify your main method.
You will also receive an error saying that outprintln is not a method of the System class. To print, use System.out.println("Your message") rather than System.outprintln("Your message").
It sounds like you're trying to access a class called "math" that does not exist in your current project or scope. Did you forget to import a particular library that you're supposed to be using?
This is the correct code:
public class Rounding {
public static void main (String[] args){
System.out.println("Hello World");
}
}
Some minor bugs which is usually done by all who start out with Java and Eclipse. The description of the error has already been given by Vulcan.

javacpp in eclipse doesn't work --ClassNotFoundException (using JNI)

I'm trying to use javacpp and encounter some difficulties with eclipse (+ mac OS).
When I run this in my command line - it works fine:
#include <string>
namespace LegacyLibrary {
class LegacyClass {
public:
const std::string& getProperty() { return property; }
void setProperty(const std::string& property) { this->property = property; }
private:
std::string property;
};
}
and
import com.googlecode.javacpp.*;
import com.googlecode.javacpp.annotation.*;
#Platform(include="LegacyLibrary.h")
#Namespace("LegacyLibrary")
public class LegacyLibrary {
public static class LegacyClass extends Pointer {
static { Loader.load(); }
public LegacyClass() { allocate(); }
private native void allocate();
public native #ByRef String getProperty();
public native void setProperty(String property);
}
public static void main(String[] args) {
LegacyClass l = new LegacyClass();
l.setProperty("Hello World!");
System.out.println(l.getProperty());
}
}
as suggested in this post
I get the end result: "hello world".
Now I'm taking this into my eclipse IDE and for some reason, I get this error:
Exception in thread "main" java.lang.NoClassDefFoundError: java.lang.ClassNotFoundException: com.test.LegacyLibrary
at com.googlecode.javacpp.Loader.load(Loader.java:293)
at com.googlecode.javacpp.Loader.load(Loader.java:271)
at com.test.LegacyLibrary$LegacyClass.<clinit>(LegacyLibrary.java:12)
at com.test.LegacyLibrary.main(LegacyLibrary.java:23)
Caused by: java.lang.ClassNotFoundException: com.test.LegacyLibrary
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 sun.misc.Launcher$ExtClassLoader.findClass(Launcher.java:229)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at com.googlecode.javacpp.Loader.load(Loader.java:291)
... 3 more
I placed the 2 files into a package com.test and the javacpp.jar I placed in the classpath.
Is there anything I'm missing here?!?! the error message indicates that something in the classpath is incorrect (or missing), but what is it? (I also tried to point in the properties to the javacpp.jar in a different folder but I get the same error message). Maybe VM arguments?!?!
Thank you!
Did you add the javacpp.jar file to the projects libraries? Go to the project properties, then the Build Path information, there should be a tab for Libraries. Add an External Jar file, and select the javacpp.jar file.
Go to Project Properties->Java Build Path, in the tab Source click on the arrow to expand the source folder, then select Native Library Location and click on Edit, After all find the path to the LegacyLibrary.h file and that should work.
My guess is that your maven file is misconfigured and hence gcc compiler cannot find your source file LegacyLibrary.h.
Configure your pom.xml using the following link as a reference.
https://github.com/oltzen/JavaCppExample/blob/master/pom.xml
Pay attention to line 53 and 65. Fill in the correct package names. This helps the compiler find out where your LegacyLibrary.h is.
Also, watch this video clip https://www.youtube.com/watch?v=LZrrqZLhtmw which walks you through the whole process how to run Javacpp with maven and eclipse.

Categories

Resources