Exception in thread "main" java.lang.ClassNotFoundException? - java

I cloned my project from GitHub and now I am not able to run my project.
package edu.test.algorithm;
import edu.test.algorithm.Global;
public class Main {
public static void main(String[] args) {
Global global= new Global();
global.runGlobal("-----url");
}
}
I am getting this error:
Exception in thread "main" java.lang.ClassNotFoundException: edu.test.algorithm.Global.Main
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)
Any idea what's causing this error?
EDIT
I checked this question Intellij suddenly throwing ClassNotFoundExceptionbefore i posted here and it doesn't give me any solution.. Why marking my question as duplicate since that one isn't solving my problem?

Maybe your Ide is wrong run/debug configuration
Main -> Edit Configuration
enter image description here
Check your IDE run configurations and Class
https://www.jetbrains.com/help/idea/2016.2/creating-and-editing-run-debug-configurations.html

The exception message hints that you have used the wrong class name when launching the program.
You are (presumably) using edu.test.algorithm.Global.Main as the class name. However you have actually declared Main in the package edu.test.algorithm which means that its full classname is actually edu.test.algorithm.Main.
If you didn't do this explicitly, it is possible1 that you changed the Main classes package and neglected to change (or remake) the launcher config.
1 - I'm not familiar with Intellij ... but I know you can run into this kind of problem with Eclipse.

Related

How to use Eclipse ClassPath via CMD or Bash?

I have one app which I want to dockerize. But first, I need to run it via console(cmd or bash). When I run it from Eclipse everything is okay, but when I run it from bash(java -jar project-18.5.0-SNAPSHOT.jar) I get this error
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
at com.hp.spacecat.util.PropertyUtil.<clinit>(PropertyUtil.java:35)
at com.hp.spacecat.SpaceCat.main(SpaceCat.java:76)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory
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)
... 2 more
I have that jar in m2 and he has this LogFactory class. Mvn clean install is success. But for some reason I can't run it via console. I don't know is there some way to get that classpath from Eclipse or there is another way to solve this.
Similar questions about this logging exception didn't help me.

I am using MCP, but when I try to launch, it gives me a ClassLoader error?

I have setup MCP with IntelliJ IDEA but I have an issue, whenever I try to launch the game, I would have to keep trying until it works, I don't know if this will help but whenever it says Task :Compiling Java, Task :processResources, and Task :classes, then it would launch but when it doesn't then it won't launch. (BTW sorry if this is the wrong place to send this question)
I haven't really tried anything because I am new to IntelliJ and I am afraid that I might press a button that I don't know what it will do it might do something that I don't want because it has already happened once, and pressing things that you don't know what it will do is also just stupid, unless it is safe to do so.
Here is the error:
Exception in thread "main" java.lang.NoClassDefFoundError:
joptsimple/OptionSpec
at Start.main(Start.java:11)
Caused by: java.lang.ClassNotFoundException: joptsimple.OptionSpec
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 1 more

Java IntelliJ Exception in Thread "main" java.lang.ClassNotFoundException:

So I've been getting this error pretty much on any new installation of IntelliJ on multiple computers.
The code I'm running is a simple hello world system out class.
public class hello {
public static void main(String[] args) {
System.out.printf("HELLO WORLD");
}
}
That's it.
Everytime I run this or anything else I get the error:
Exception in thread "main" java.lang.ClassNotFoundException: hello
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:123)
I've tried:
Revalidating my cache files
recompiling the project
setting the environmental variables to find the jdk and jre installations
setting the correct source folders
reinstalling jdk on windows and installing on ubuntu
at one stage I had managed to get it running when i used a default java class template on something, it had a import or package statement, but I can't remember what it was, however after adding the import/package statement things had worked.
UPDATE: the package that appears to get it working is "package com.company;", why does this work? what does it do?
Any help would be greatly appreciated.
Thanks Guys.

Exception in thread "main" java.lang.ClassNotFoundException:

I recently installed intellij IDEA 14.0 and to make sure everything was working I created a simple Hello World program. I do not understand why the output is not correct and why I am getting this error. If someone could please help that would be great.
This is the program:
public class Hello {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}
This is the error:
Exception in thread "main" java.lang.ClassNotFoundException: Hello
at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:260)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:116)
The reason you're getting this error is because you didn't save the class into a file called Hello.java (case-sensitive!)
This is just problem of intellij IDE.
Solution Steps:
CtrlShiftAlts -> Preject Setting -> modules tab -> expand <project_name> and go to <project_name>_main
refer Image:
In Sources tab -> ** click on x symbol**
click YES
Right click on -> sources
Apply and OK
Finally build your project.
Enjoy.
It usually happens with IntelliJ.
I solved it deleting all modules and only leaving which have more hierarchy
The other modules(like main or test) are already part of product

Why won't this project run NetBeans, but it does in Eclipse

I have built a small program for school that runs perfectly when i run it through eclipse, but if I run the same code in NetBeans I get this error:
java.lang.NoClassDefFoundError: myrunnable/Main
Caused by: java.lang.ClassNotFoundException: myrunnable.Main
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:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
Could not find the main class: myrunnable.Main. Program will exit.
Exception in thread "main" Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)
How do i fix this?!
I have not used netbeans but from what I can see from your exception looks to me JRE may not be in the classpath. Have you checked that? For example when you create a project in eclipse it will automatically add JRE to the classpath.
OR
may be you need to explicitly compile/build before you can run. In eclipse it is auto too. When you run a simple.java it would have created the corresponding simple.class in the bin output folder.
Check those two areas you will be fine I think
Is there a main method defined in the class?
public static void main(String[] args) {
}
Also, is your Java JDK properly registered inside Netbeans?

Categories