olipinski
olipinski

Reputation: 103

Scanner no class error

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. :)

Upvotes: 0

Views: 455

Answers (3)

Konstantin Komissarchik
Konstantin Komissarchik

Reputation: 29139

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

Upvotes: 0

Mike Samuel
Mike Samuel

Reputation: 120576

When you're running java, don't put .java on the end of the class name.

Upvotes: 3

Ernest Friedman-Hill
Ernest Friedman-Hill

Reputation: 81724

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

Upvotes: 2

Related Questions