I'm new to java and i have a problem while trying to run my program. I'm using eclipse.
import java.util.Scanner;
public class Scan {
public static void main(String[] args) {
String imie;
Scanner odczyt = new Scanner(System.in);
imie=odczyt.nextLine();
System.out.println("Witaj "+imie);
}}
This what I get:
EDIT(Runned without dot)
Exception in thread "main" java.lang.NoClassDefFoundError: Scan
Caused by: java.lang.ClassNotFoundException: Scan
开发者_运维知识库 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: Scan. Program will exit.
Please help me. :)
When you're running java
, don't put .java
on the end of the class name.
It looks like you're trying to run a class named Scan.java
, but there is no such class; the class is just named Scan
. However you're launching your class, you need to launch just Scan
, i.e.,
java Scan
not
java Scan.java
You need to specify classpath that specifies where Scan class can be found. The classpath can point to a folder of classes or a JAR file. For instance...
java -cp scan.jar Scan
精彩评论