简体   繁体   中英

How to resolve this error Caused by: java.lang.ClassNotFoundException

I wrote a console application helloworld.java and ran javac helloworld.java ,and then java helloworld . This worked fine.

I then created a package com.abc.project and moved helloworld.java into it(the package import statement is correctly generated which is package com.abc.project; ). And then i ran javac helloworld.java this worked also fine and generated the class properly.

However, when I ran java com.abc.project.helloworld from the console, it threw an "class not found" error.

Please can anyone advise what is the problem?

Try running

java -cp ABSOLUTE_PATH com.abc.project.helloworld

Where ABSOLUTE_PATH refers to the directory where the class files along with packages are present. say it is bin directory where the class files are generated along with same directory structure as source files

First Please name Class with Capital Letter like HelloWorld.java

If you are in a folder '/myjava' in cmd and your .java files is in this folder then do this in cmd

D:\\myjava\:> javac -d HelloWorld.java

This will create correct package Structure for you Then don't go anywhere from the same location do this

D:\\myjava\:>  java com.abc.project.HelloWorld

It should work fine!!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM