This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Java in General and the fly likes Java code do not execute Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Java code do not execute " Watch "Java code do not execute " New topic

Java code do not execute

Alpesh Gediya

Joined: Nov 23, 2009
Posts: 24
Hello, Friends

public class Test

public static void main(String ars[])

when i compile above code at [b] windows desktop[/b] and .class file also generates if try to run than i am getting "NoSuchMethodError".
but if i compile above code at location other than windows desktop and copy class file to windows desktop then it executes fine.

code that compiled at other than windows desktop location , if i copy that .class file to windows desktop and use try to run then it works as expected.
but .class generated at windows desktop do not execute at any other location.

please help me on this...

Enviorment varible is set.

i manually set classpath at windows desktop location then also it's not working.

Alpesh Gediya
Do not re-invent the wheel.
Somnath Mallick
Ranch Hand

Joined: Mar 04, 2009
Posts: 482
Well check if the windows desktop folder has execution rights or not! Could be a access rights issue. Just a guess though!
Alpesh Gediya

Joined: Nov 23, 2009
Posts: 24
I have administrator right for my account.
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42965
What, exactly, are you typing at the command line to run that class? Something like "java Test" should do the trick no matter in which directory you are.

Since you mention the CLASSPATH variable, I'd advise not to use that. It's generally less troublesome to specify any directories or libraries as part of the command (using the "-cp" switch). Note that all paths needs to be put into double quotes if they contain spaces.
Alpesh Gediya

Joined: Nov 23, 2009
Posts: 24
Hello, Ulf Dittmer

Its working fine now, but i still not understand why that was happening. even though i set CLASSPATH.
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46424
Don't set a system classpath.
I agree. Here's the link:
subject: Java code do not execute
It's not a secret anymore!