I wonder why the Game.class wont start. Here's he problem I got:
java.lang.NoClassDefFoundError: Game (wrong name: game/Game)`
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
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)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
Exception in thread "main"
You will get similar error if you do mething like this:
package game;
class Game
{
public static void main(String[] args)
{
System.out.println("Hello World!");
}
}
without putting the compiled class file in a sub-folder called game and run it like java Game. So your Game class is in a package called game.
Please Check Your packaging structure and ensure that your class file is inside the package folder . Compile and Happy Execution ....
Related
Here's my simple code:
import static com.jayway.restassured.RestAssured.get;
public class testget {
public static void main(String[] args) {
Response countryName = get("http://maps.googleapis.com/maps/api/geocode/json?latlng=45.2542285874,30.2564857&sensor=false");
System.out.println(countryName);
System.exit(0);
}
}
When running, I get the following error:
Exception in thread "main" java.lang.NoClassDefFoundError: com/jayway/restassured/mapper/factory/ObjectMapperFactory
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
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)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at com.jayway.restassured.config.RestAssuredConfig.<init>(RestAssuredConfig.java:41)
at com.jayway.restassured.RestAssured.<clinit>(RestAssured.java:423)
at testeget.main(testeget.java:6)
Caused by: java.lang.ClassNotFoundException: com.jayway.restassured.mapper.factory.ObjectMapperFactory
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 15 more
But the Rest Assured lib is loaded, otherwise the get method wouldn't even be called... What could it be?
I'm using Rest Assured 2.8.
Update:
I'm using Eclipse to run it, and the classpath has, besides the default Java/Eclipse content, the path to the .jar file of Rest Assured and it's dependencies, as listed on their website.
Dependencies list on the bottom of the page (all added to the classpath).
http://mvnrepository.com/artifact/com.jayway.restassured/rest-assured/2.8.0
How to run a Sikulix.class ?
This is the error I'm getting.
D:\test_sikuli\sikulix>java -cp D:\test_sikuli\sikulix\org\sikuli\ide SikuliIDE
Exception in thread "main" java.lang.NoClassDefFoundError: SikuliIDE (wrong name: org/sikuli/ide/SikuliIDE)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
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)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
The class you want to run is apparently org.sikuli.ide.SikuliIDE. You need to set the classpath to the top folder and not to the package folder and use the qualified class name.
D:\test_sikuli\sikulix>java -cp D:\test_sikuli\sikulix org.sikuli.ide.SikuliIDE
I have a Dynamic Web Project in Java and I use Jena and D2RQ libraries.
When I start my project as "Java Application", I have this problem:
Exception in thread "main"
java.lang.IncompatibleClassChangeError: Implementing class at
java.lang.ClassLoader.defineClass1(Native Method) at
java.lang.ClassLoader.defineClass(Unknown Source) at
java.security.SecureClassLoader.defineClass(Unknown Source) at
java.net.URLClassLoader.defineClass(Unknown Source) at
java.net.URLClassLoader.access$100(Unknown Source) 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) at
java.lang.ClassLoader.loadClass(Unknown Source) at
sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at
java.lang.ClassLoader.loadClass(Unknown Source) at
de.fuberlin.wiwiss.d2rq.algebra.CompatibleRelationGroup.addNodeRelation(CompatibleRelationGroup.java:53)
at
de.fuberlin.wiwiss.d2rq.algebra.CompatibleRelationGroup.groupNodeRelations(CompatibleRelationGroup.java:38)
at de.fuberlin.wiwiss.d2rq.find.FindQuery.iterator(FindQuery.java:78)
at
de.fuberlin.wiwiss.d2rq.jena.GraphD2RQ.graphBaseFind(GraphD2RQ.java:88)
at com.hp.hpl.jena.graph.impl.GraphBase.find(GraphBase.java:240) at
com.hp.hpl.jena.graph.compose.DisjointUnion.graphBaseFind(DisjointUnion.java:27)
at com.hp.hpl.jena.graph.impl.GraphBase.find(GraphBase.java:240) at
com.hp.hpl.jena.graph.impl.GraphBase.graphBaseFind(GraphBase.java:260)
at com.hp.hpl.jena.graph.impl.GraphBase.find(GraphBase.java:257) at
com.hp.hpl.jena.graph.query.SimpleQueryHandler.predicatesFor(SimpleQueryHandler.java:68)
at
com.hp.hpl.jena.graph.query.SimpleQueryHandler.predicatesFor(SimpleQueryHandler.java:47)
at
com.hp.hpl.jena.rdf.model.impl.ModelCom.listPredicates(ModelCom.java:751)
at
com.hp.hpl.jena.rdf.model.impl.ModelCom.listNameSpaces(ModelCom.java:763)
at
com.hp.hpl.jena.xmloutput.impl.BaseXMLWriter.addNameSpaces(BaseXMLWriter.java:233)
at
com.hp.hpl.jena.xmloutput.impl.BaseXMLWriter.setupNamespaces(BaseXMLWriter.java:487)
at
com.hp.hpl.jena.xmloutput.impl.BaseXMLWriter.write(BaseXMLWriter.java:469)
at MyPackage.MyClass.Mymethod(MyClass.java:118) at
MyPackage.Test.main(Test.java:77)
The row 118 of the class "MyClass" contains this code:
writer.write(d2rqModel, new OutputStreamWriter(out, "utf-8"),loader.getResourceBaseURI());
with
RDFWriter writer;
and
import com.hp.hpl.jena.rdf.model.RDFWriter;
Why I have this problem?
In addition, the same class in a different project works well!!! Why?
You've changed and recompiled the class without recompiling everything that depends on it. Do a clean build. You may get some compiler errors in the process.
You may have added dependency that are ambiguous to compiler's understanding. Verify that you don't have duplicate dependency for same class.
I am currently trying to build a simple java Game with Slick and Maven.
My Setup does work basicly. But when I extend my Main Class to be a Slick "BasicGame" I can't execute the jar anymore, promting this error message:
D:\workspace\GameTest\target>java -jar GameTest-1.0-SNAPSHOT.jar
Exception in thread "main" java.lang.NoClassDefFoundError: org/newdawn/slick/BasicGame
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(Unknown Source)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$000(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
Caused by: java.lang.ClassNotFoundException: org.newdawn.slick.BasicGame
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 12 more
Could not find the main class: gameTest.MyGame. Program will exit.
Before I did this everything executed just fine. The Pom.xml is copied from here.
the MyGame class looks like this:
...
imports
...
public class MyGame extends BasicGame {
...
empty implementations of BasicGame Methods
...
public static void main(String[] args){
System.out.println("Hello World");
}
}
Does anyone know why this error occures?
Does anyone know why this error occurs?
When you switched to using an executable jar, you created a situation where your dependent library - slick.jar - is no longer in your class path. Everything starts out OK because MyGame is in your jar file. But MyGame extends BasicGame which is not in your jar file. It is in slick.jar and your java command makes no reference to slick.jar.
Somehow you have to get all your dependencies back into your class path. For more information check out related question Is it possible to create an "uber" jar containing the project classes and the project dependencies as jars with a custom manifest file?
Just checked your pom.xml file - you'll have to integrate lwjgl and vecmath into your class path also.
I want to encrypt a string, but the standard Java libraries are too complicated for me.
So I turned to Jasypt labriry. It's pretty simple to use and understan. However when I import the library to Eclipse 3.6 and when I try encrypt a string like "Hello" with the password "123", it always comes up with an error. I'm not sure what I'mm doing wrong but I think it also happens when I use other libraries in Eclipse.
Source:
import org.jasypt.util.text.BasicTextEncryptor;
public class Main {
static BasicTextEncryptor textEncryptor = new BasicTextEncryptor();
public static void main(String[] args) {
System.out.println("Hello World");
textEncryptor.setPassword("123");
System.out.println(textEncryptor.encrypt("Hello World"));
}
}
The error message:
java.lang.NoClassDefFoundError: org/apache/commons/lang/exception/NestableRuntimeException
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(Unknown Source)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$000(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at org.jasypt.util.text.BasicTextEncryptor.<init>(BasicTextEncryptor.java:67)
at eMain.<clinit>(eMain.java:4)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.lang.exception.NestableRuntimeException
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 14 more
The library you imported depends on another library containing org/apache/commons/lang/exception/NestableRuntimeException. This is located in the Apache Commons Lang library.
In fact, if you downloaded JASYPT from http://sourceforge.net/projects/jasypt/files/ you'll get a zip file containing a lib-folder with these files:
commons-codec-1.1.jar
commons-lang-2.1.jar
jasypt-1.6.jar
You should include all of these in your project.
I tried it and your little sample program works fine (and prints the following)
Hello World
v09l9j/BIeSoMkQXc2CY0VIJLlLAQTYq