I am facing an error when run the below java program on windows command prompt. Basically, I am a C/C++ programmer, but i need to run a java file as a part of some testing..
Following is the content of my TestClass.java, not copied full code as it looks like some kind of path or package issue.
package parse_signature;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
public class TestClass {
public static void main(String[] args) throws IOException {
String path_of_file= "input/content.txt";
BufferedReader reader = new BufferedReader(new FileReader(path_of_file));
String line;
while ((line = reader.readLine()) != null) {
....
}
}
I am in the directory: C:/Users/Desktop/JavaPRGs/Test/
, when i used the command javac TestClass.java
,
TestClass.class
got created and when i run java TestClass
I get following error:
Error: Could not find or load main class TestClass
Caused by: java.lang.NoClassDefFoundError: parse_signature/TestClass (wrong name: TestClass)
I tried going back to previous directory C:/Users/Desktop/JavaPRGs
and ran java Test.TestClass
got the same error (only this difference wrong name: Test/TestClass)
Also tried follwing, but the result is same.
C:\Program Files\Java\jdk-12.0.1\java -cp . Test.TestClass
You need to remove the package and try to compile and run it again using javac TestClass.java
and java TestClass
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.