SlickUtil - NoClassDefFoundError when accessing API - java

When I try to do anything with SlickUtil, I get this error
Exception in thread "main" java.lang.NoClassDefFoundError: org/newdawn/slick/opengl/renderer/Renderer
at org.newdawn.slick.TrueTypeFont.<clinit>(TrueTypeFont.java:28)
at Text.init(Text.java:14)
at Main.main(Main.java:78)
Caused by: java.lang.ClassNotFoundException: org.newdawn.slick.opengl.renderer.Renderer
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 3 more
Code
public static Font font;
public static TrueTypeFont uf;
public static void main (String[] args) {
font = new Font("Times New Roman", Font.BOLD, 20);
uf = new TrueTypeFont(font, true); // Throws the error
}
public static void render (String text) {
uf.drawString(0, 0, text);
}
Why is this error being thrown, and what can I do about it?
Otherwise, is there a method to display 2D text with OpenGL without using SlickUtil?

Why is this error being thrown, and what can I do about it?
It is being thrown because the JAR file containing that dependency is not on the runtime classpath. (Apparently, the JAR file was available when your application was compiled. If it wasn't, then the source code that refered to the class would not have compiled.)
What you need to do is to find / identify the JAR file, and add it to the runtime classpath of your application.
Is there a method to display 2D text with OpenGL without using SlickUtil?
That is a request for us to find or recommend software for you. It is off-topic.
And moot ... if you sort out the real problem with your classpaths.

Related

glfwInit() is throwing an IllegalStateException error on initialization

I am trying to set up GLFW, but so far, I am getting stuck on the very first step, which is calling glfwInit(). My code is below:
import static org.lwjgl.glfw.GLFW.*;
public class Main {
public static void main(String[] args)
{
if(!glfwInit())
{
throw new IllegalStateException("Failed to initialize GLFW");
}
}
}
I am getting this error: Exception in thread "main" java.lang.ExceptionInInitializerError at org.lwjgl.glfw.GLFW.glfwInit(GLFW.java:1046) at Main.main(Main.java:6) Caused by: java.lang.IllegalStateException: GLFW may only be used on the main thread and that thread must be the first thread in the process. Please run the JVM with -XstartOnFirstThread. This check may be disabled with Configuration.GLFW_CHECK_THREAD0. at org.lwjgl.glfw.EventLoop.<clinit>(EventLoop.java:30).
For reference, I am on a Mac, and am using eclipse, and have every single LWJGL jar file included in the project classpath.
Will running JVM with -XstartOnFirstThread like the warning says fix the issue? And if so, how do I do it?

Java -> including robot class in eclipse

I would like to work with this robot class :
http://docs.oracle.com/javase/1.5.0/docs/api/java/awt/Robot.html
for generating native system input´s, thats why i created this file:
import java.awt.Robot;
public class MouseClass {
public static void main(String[] args) throws Exception {
Robot robot = new Robot();
// SET THE MOUSE X Y POSITION
robot.mouseMove(300, 550);
}
}
but i got this error-msg:
Exception in thread "main" java.lang.NoClassDefFoundError: robot/robot_v1
Caused by: java.lang.ClassNotFoundException: robot.robot_v1
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)
I thought, the awt.robot is already integrated in eclipse? ok if not..i dont know where to download this robot-class, the only page i found is:
http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/6-b14/java/awt/Robot.java
but thats "Robot.java" and the error-message doent change when i include this in my "src".
Any advices how i can use this robot-class?
SOLVED ,but:
i get a compilation problem
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
at robot.robot_v1.main(robot_v1.java:5)
For this line:
public static void main(String[] args) throws Exception {
do i have to change name´s here as well in this case?
greetings
=> SOLDED with package robot;
Your issue is not related to Robot class at all. There is mismatch between your java file name and class name.
Your java class as you meantion in comment is robot/robot_v1.java and your class name is MouseClass. To make it work, all what you need to do is change your class name to be same as file which will be robot_v1 and as it is not in default package, you need to add at beginning of your file package definition, which will be for this case package robot;

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.

OpenGL in Java on Netbeans: NoClassDefFoundError

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

Got 'java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory` in code using JasperReports API

I am working on a simple standalone desktop application which would generate report based on the values passed to the program. There is no database usage. I have designed my JasperReports report with the iReport designer and added a parameter ID_NO and a text field with expression $P{ID_NO}
I can preview the report successfully and see what I expected. But I cant generate the report from Java application and pass the parameter ID_NOfrom there. Here is my code:
public class MyReportViewer extends JFrame {
public MyReportViewer(String fileName) {
this(fileName,null);
}
public MyReportViewer(String fileName,HashMap<String, Object> parameter) {
super("View Report");
try {
JasperPrint print = JasperFillManager.fillReport(fileName, parameter);
JRViewer viewer = new JRViewer(print);
Container c = getContentPane();
c.add(viewer);
} catch(Exception e) {
e.printStackTrace();
}
setBounds(10, 10, 600,500);
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
}
public static void main(String args[]) {
HashMap<String, Object> param = new HashMap<String, Object>();
param.put("ID_NO", "101-15-980");
MyReportViewer viewer = new MyReportViewer("test.jasper", param);
viewer.setVisible(true);
}
}
The code gives a exception
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
at net.sf.jasperreports.engine.util.JRLoader.<clinit>(JRLoader.java:61)
at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:267)
at jspertest.MyReportViewer.<init>(MyReportViewer.java:37)
at jspertest.MyReportViewer.main(MyReportViewer.java:60)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
And does not run.
Please give me a clue. I have never used JasperReports or any kind of report generator before.
Edit:
Added all the library files from jasperreports4.x.x/lib/.. to the project. Now the exception is gone. Now the console says-
log4j:WARN No appenders could be found for logger (net.sf.jasperreports.extensions.ExtensionsEnvironment).
log4j:WARN Please initialize the log4j system properly.
and a small popup says there are no pages in the document. A small windows appears with no report in it.
Your exception is not related with the Parameter issue, which apparently looks good.
It looks like you are missing Apache Commons Logging in your classpath. It runs in preview mode because your IDE does have the correct classpath.
Yeah that's right. "The document has no pages" means there are no records in the datasource, thus no report is generated.
You can set the property in which the report will still display the blank pages even when the data is not present in the report.
When NO Data property will allow you to choose different values and different way of showing the report in case the dataset returns zero rows or the report has not data to print.

Categories

Resources