hi All,
I've just start java have a problem with compiling an Application.
First i done Coding :

/* This program Will take two arguments Hello world from the command Prompt and prints them to standard console. If you specify less then two arguments an exception Will be thrown*/

public class TwoArgsApp {

public static void main(String args[]){

//Displays the first argument on console
  System.out.println("First argument"+args[0]);

//Displays the second argument on console
  System.out.println("Second argument"+args[1]);
 }
}

And when I've try to compile the App its don't print on console give the Eror you can see here :

D:\>set path=C:\Program Files\Java\jdk1.6.0_27\bin

D:\>javac TwoArgsApp.java

D:\>java TwoArgsApp
Exception in thread "main" java.lang.NoClassDefFoundError: TwoArgsApp
Caused by: java.lang.ClassNotFoundException: TwoArgsApp
        at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
Could not find the main class: TwoArgsApp.  Program will exit.

D:\>

would you like to mention,where i was done mistake ?
or is it jdk version problem ?

Thanks in Advance
usman

Build and runs fine here:
java version "1.6.0_23"
OpenJDK Runtime Environment (IcedTea6 1.11pre) (6b23~pre10-0ubuntu5)
OpenJDK Server VM (build 20.0-b11, mixed mode)


So I think it is better you uninstall and re install your jdk. may be it is corrupt

I've install jdk Second time. but problem still there :(

In your set path command, try putting the path in "double quotes".
The space in "Program Files" may be causing an error.

you mean i should try this : "C:\ProgramFiles\Java\jdk1.6.0_27\bin"
gonna try this.

now the Error is:

D:\>set path="C:\Program Files\Java\jdk1.6.0_27\bin"

D:\>javac TwoArgsApp.java
javac: file not found: TwoArgsApp.java
Usage: javac <options> <source files>
use -help for a list of possible options

D:\>

:(

when im compiling by this path : C:\Program Files\Java\jdk1.6.0_27\bin
its goes successfully till making Class file and after create a class file its dose not print on console by this command : java TwoArgsApp
:(

Try this... Change...

public static void main(String args[]){

to

public static void main(String[] args){

Edited 5 Years Ago by Taywin: n/a

@Taywin that doesn't matter, it is only coding convenience
@us0343 why don't you set proper path in your system variables instead of fiddling each time with set path, you can see example here

This article has been dead for over six months. Start a new discussion instead.