cannot run a simple java code

前端 未结 5 1677
离开以前
离开以前 2021-01-22 11:45

I have downloaded a java developers kit for my 64bit windows 7, wrote down my code in the notepad, though the code is compiling from the command prompt and creating a .class fil

相关标签:
5条回答
  • 2021-01-22 12:21

    You must provide with the code.

    Anyway, from the Java Docs, class ClassNotFoundException:

    Thrown when an application tries to load in a class through its string name using:

    • The forName method in class Class.
    • The findSystemClass method in class ClassLoader.
    • The loadClass method in class ClassLoader.

    but no definition for the class with the specified name could be found.

    Must read link : Tip: Causes of java.lang.ClassNotFoundException

    0 讨论(0)
  • 2021-01-22 12:23

    It is quite possible after compiling your code you would be writing java filename.java. Because this sought of exception occurs then.

    After compiling your program using javac filename.java use the command to start your interpreter java filename.

    As you enter this command java interpreter automatically starts interpreting filename.class.

    commands :

    javac filename.java   // to start compiling
    java filename         // to start interpreting
    
    0 讨论(0)
  • 2021-01-22 12:30

    A java program has this basic structure:

    ClassName.java

    public class ClassName
    {
        public static void main(String[] args)
        {
    
        }
    }
    

    try using this outline to generate your code.

    compile and run with:

    javac ClassName.java
    java ClassName
    
    0 讨论(0)
  • 2021-01-22 12:40

    Did you set your classpath?

    http://download.oracle.com/javase/1.3/docs/tooldocs/win32/classpath.html

    java -classpath <path> <classname>
    
    0 讨论(0)
  • 2021-01-22 12:42

    I used to get this error when I ran a Class file.

    Try doing: java NameOfClass

    You don't need the .java extension when running, but you need it for compiling. That was always the problem I used to have.

    0 讨论(0)
提交回复
热议问题