error while running main function without libgdx - java

I have been using libGdx for a while now. I have created a new project without using libGdx and created some class trying to practice some code if it works as I intended. However, I'm getting error that main class is not found in the libgdx package.
How Do I switch between libgdx and just native IDE.
So for example...
package com.example.example;
public class Example
{
public static void main (String[] args)
{
System.out.println("hey");
}
}
when i try to run this code I get error
Exception in thread "main" java.lang.NoClassDefFoundError: com/badlogic/gdx/jnigen/BuildTarget$TargetOs
at com.badlogic.gdx.physics.box2d.utils.Box2DBuild.main(Box2DBuild.java:13)
Caused by: java.lang.ClassNotFoundException: com.badlogic.gdx.jnigen.BuildTarget$TargetOs
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)
... 1 more
How do I fix this? Thanks in advance!

I ran into this error today and Lestat was correct.
In your IDE (in my case Eclipse): go to Run> Run As> Java application.

Related

Java Eclipse ClassNotFoundException after importing external JARs

I'm getting a ClassNotFoundException when I try to execute the following code:
import org.apache.commons.text.WordUtils;
public class CapitalizeFirstLetters {
public static void main(String[] args) {
String str="this is a test";
str=WordUtils.capitalizeFully(str);
System.out.println(str);
}
}
I'm new to importing libraries in Java. Here is what my Package Explorer and Build Path look like (I closely followed advice from other people asking similar questions).
Project Explorer ,
Java Build Path
and here is the error text:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/lang3/StringUtils
at org.apache.commons.text.WordUtils.capitalizeFully(WordUtils.java:494)
at org.apache.commons.text.WordUtils.capitalizeFully(WordUtils.java:464)
at CapitalizeFirstLetters.main(CapitalizeFirstLetters.java:7)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.lang3.StringUtils
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)
... 3 more
Can anyone please help me with this? I cannot find the answer for this problem in Eclipse anywhere online. So far I have tried: deleting everything and starting over.
Thank you!

Successfully implementing external classes in Eclipse. (Java)

I have been trying to use this external class folder which was given from my programming lecturer a few months back. I followed people's explanations of how to add via "configure build class", and the application somewhat recognises the class because a shortlist of some of the methods are given. It also does not return any errors prior to runtime but once it's ran I get this:
Exception in thread "main" java.lang.NoClassDefFoundError: Console
at lab3.q2.main(q2.java:15)
Caused by: java.lang.ClassNotFoundException: Console
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)
... 1 more
This is really frustrating as it works from the linux computers in my college without issue. The class file is just a variation of the scanner that we use for user i/o, I have it attached.
Console.class file

Java EWS throws NoClassDefFound

I want to read the Outlook calendar. So I'm started first to try to connect to the server. I found http://code.msdn.microsoft.com/exchange-ews-java-api-12-1a5a1143 and want just to get the connect and try around.
I found a example and tried this:
import microsoft.exchange.webservices.data.*;
...
public void test(){
ExchangeService es = new ExchangeService();
ExchangeCredentials credentials = new WebCredentials("user", "Password");
}
It crashes by Exchange Service:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/httpclient/HttpConnectionManager
at ExchangeTest.test(ExchangeTest.java:15)
at Window.main(Window.java:19)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.httpclient.HttpConnectionManager
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)
... 2 more
I tried to import a library but didn't got the correct one or the fault is something else. Can you tell me which library I need or where/how I can fix it. Thanks.
I'm using a Win7.
You need this library The Commons HttpClient and you have to add this library to the build path of your project.

Junit in eclipse produces NoClassDefFoundError when using junit

I am new to jUnit and unit testing in general, and have been trying to set up my testing environment and failing all day. This is trying to test a method in my android application.
I added a test class to the same package the java class is in. I added a method as below:
#Test
public void testIsExpectedNote() {
assertTrue(Frequency.isExpectedNote(440, "A"));
}//should return true
This fails with the following stack trace:
java.lang.NoClassDefFoundError: android/util/Log
at dataLogicLayer.Frequency.isExpectedNote(Frequency.java:13)
at dataLogicLayer.FrequencyTest.testIsExpectedNote(FrequencyTest.java:11)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
...
Caused by: java.lang.ClassNotFoundException: android.util.Log
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)
... 25 more
Any ideas what is going wrong? I have been playing with my run configurations and in the classpath i have:
jre system library [jre7]
junit 4
Do you have the android sdk in your classpath? search for the jar containing the class android.util.Log in your classpath
regards
Grub
The answer was to make a new project and do testing in there instead, must make it an android junit test, and make sure the run configs are correct. thanks to Grub for your help
Seems like you are mixing Android SDK and Java SDK. You should not be doing that. Android is a self sufficient library.

Error NoClassDefFoundError/ClassNotFoundException

after about a month of not opening eclipse at all, I get a strange error
java.lang.NoClassDefFoundError: Z
Caused by: java.lang.ClassNotFoundException: Z
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)
Exception in thread "main"
I don't really understand what it wants, it doesn't show me anything else, something about main class "Z" not being defined? but it is, isn't it?
[CODE][/CODE] doesn't work very well here so I'll put source here: http://pastebin.com/heMhDqU2
Thank you.
Edit 1: it shows me when I try to compile and run. Btw, indent code by using 4 spaces for 500 lines... seems kinda reduntant
Your code is fine it compiles here.
Most probably an eclipse error.
Try this.
Close eclipse
Start eclipse with the flag .../eclipse.exe -clean
Press Project -- > Clean

Categories