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
Related
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.
I am trying to run a tutorial from here Office Open XML. I have downloaded the Docx4j library and added it to the netbeans as a library.
the code snippet is given below
import org.docx4j.openpackaging.exceptions.Docx4JException;
import org.docx4j.openpackaging.packages.WordprocessingMLPackage;
public class OfficeOpen {
public static void main(String[] args) throws Docx4JException {
WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.createPackage();
wordMLPackage.getMainDocumentPart().addParagraphOfText("Hello Word!");
wordMLPackage.save(new java.io.File("src/main/files/HelloWord1.docx"));
}
}
when I run the above example I get the following error
Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
at org.docx4j.openpackaging.Base.<clinit>(Base.java:43)
at officeopen.OfficeOpen.main(OfficeOpen.java:24)
Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
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)
... 2 more
Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)
looks like the JVM cannot find a class at run time, any suggestion. I am using Netbeans 8.0
You are missing some libraries that docx4j depends on. See http://htmlpreview.github.io/?https://github.com/plutext/docx4j/blob/master/docs/Docx4j_GettingStarted.html at docx4j dependencies.
Indeed you are missing slf4j that docx4j uses for for logging: http://www.docx4java.org/docx4j/docx4j-3_2_0/dependencies/slf4j-api-1.7.5.jar
Possibly you'll need many others.
I think this are all the dependencies, althought you may not need all of them: http://www.docx4java.org/docx4j/docx4j-3_2_0/dependencies/
I am getting the following error
Exception in thread "main" java.lang.NoClassDefFoundError: org/jsoup/Jsoup
at Main.main(Main.java:42)
Caused by: java.lang.ClassNotFoundException: org.jsoup.Jsoup
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
... 1 more
Now what I have done so far:
I created a libs folder in my project folder and added the Jsoup.jar there. Then in eclipse I click properties, add external Jar and added it. I see the referenced library.
But the issue still persist. I dont get compilation errors. So this is a runtime issue. Appreciate the help.
Edit:
I have found the following
If I compile using
javac -classpath /path/to/jsoup.jar myclass.java
and then
java -classpath /path/to/jsoup.jar myclass
It runs perfect.
Now. This is not working for me because I am going to use my application on a computer that does not have Jsoup. So how to I resolve this runtime issue?
Go to Run configurations... menu and check classpath for Run task. It looks like you add library for Compilation step, but it doesn't set at Run step.
Edit (after comment)
I dove into the issue and found that this dependency is needed for application container. So you just need to add this library to classpath of your app server. If you use Tomcat, just put the library to the %CATALINA_HOME%\lib directory.
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?
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.