So I usually run my programs through Eclipse but I’m not allowed to use it in an upcoming competition, so I started trying to compile my programs through command prompt, and I kept getting the same error for everything I tried to compile… I have searched for answers but none of them seemed to be my problem. I’d appreciate it if someone could tell me what I am doing wrong. Thank you and sorry if there is already an answer to this.
C:\Users\DanielH\Desktop\Folder>javac Test.java
C:\Users\DanielH\Desktop\Folder>java Test.class
Exception in thread "main" java.lang.NoClassDefFoundError: Test/class
Caused by: java.lang.ClassNotFoundException: Test.class
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)
Could not find the main class: Test.class. Program will exit.
Test.java was written as:
import java.util.*;
import java.io.*;
public class Test {
public static void main(String[] arguments){
Scanner fish=new Scanner(System.in);
int a=fish.nextInt();
int b=a-10;
System.out.println(b);
}}
Try
java Test. The.(dot) is a package separator, so the JVM is trying to find the class namedclassin the folderTest(seeNoClassDefFoundError: Test/class)