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

Recommended Answers

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

Jump to Post

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

Jump to Post

No. I mean "C:\Program Files\Java\jdk1.6.0_27\bin"

Jump to Post

Is your TwoArgsApp.java on the root of D: or in a sub-directory of D:?

Jump to Post

All 14 Replies

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 :(

Member Avatar

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.

Member Avatar

No. I mean "C:\Program Files\Java\jdk1.6.0_27\bin"

im doing wait a moment please.

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
:(

Member Avatar

Is your TwoArgsApp.java on the root of D: or in a sub-directory of D:?

Try this... Change...

public static void main(String args[]){

to

public static void main(String[] args){

@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

I see. Thanks for pointing out. Because I never use args[], I didn't know that. :)

on the root of D:

on the root of D:

Your comment doesn't make any sense

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.