Sponsors: Michael Fertik - Best JAVA Web hosting Company & 30% off


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-19-2010, 03:14 PM
Member
 
Join Date: Mar 2010
Posts: 8
Rep Power: 0
jttslg is on a distinguished road
Default command line arguments
how to use the commandline argument
i get the following error:
c:\users\jtt\documents> java Echo one two three
Exception in thread "main" java.lang.NoClassDefFoundError: Echo
Caused by :java.lang.ClassNotFoundException: Echo
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPriviledged(Nativ e Method)
at java.net.URLClassLoader.findClass(Unknown Source)........
Could not find the main class: Echo. Program will exit.

Please help
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 03-19-2010, 03:23 PM
j2me64's Avatar
Senior Member
 
Join Date: Sep 2009
Location: Zurich, Switzerland
Posts: 480
Rep Power: 2
j2me64 is on a distinguished road
Default
is Echo.java compiled with javac without errors? looking at the erros i don't believe. so post your Echo.java code here.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 03-20-2010, 02:41 AM
Member
 
Join Date: Mar 2010
Posts: 8
Rep Power: 0
jttslg is on a distinguished road
Default command line argument
yes echo.java is compiled ...
public class Echo
{
public static void main(String args[])
{
for (int i=0;i<args.length;i++)
System.out.println("args[" + i + "]: "+args[i]);
}
}
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 03-20-2010, 06:06 AM
Senior Member
 
Join Date: Feb 2009
Posts: 661
Rep Power: 2
pbrockway2 is on a distinguished road
Default
Go to the directory (folder) containing Echo.class and run the program with the following command:

Code:
java -cp . Echo


The "-cp" tells the java executable where to look for classes. And the dot means "here, in this directory".
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 03-20-2010, 07:15 AM
Member
 
Join Date: Mar 2010
Posts: 11
Rep Power: 0
nigamsir is on a distinguished road
Default cmd line arg
1. install jdk
2. install netbeans
3. set command line arguments from project properties
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 03-21-2010, 10:09 PM
Member
 
Join Date: Mar 2010
Location: Troy Upstate New York USA (Not in New York City)
Posts: 25
Rep Power: 0
The_Sponzy_Paradox is on a distinguished road
Send a message via AIM to The_Sponzy_Paradox Send a message via Yahoo to The_Sponzy_Paradox Send a message via Skype™ to The_Sponzy_Paradox
Default
I think the problem is that your echo class is in a different directory. Move echo into the same place as your main and then recompile both of them. After that it should run.
__________________
You know that line between genius and insanity? I am told I crossed it and went around back to insanity again.
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 03-22-2010, 12:56 PM
Member
 
Join Date: Mar 2010
Posts: 8
Rep Power: 0
jttslg is on a distinguished road
Default command line
i tried the given suggestions but the error remains the same.... i am using jdk1.6.0_17
Bookmark Post in Technorati
Reply With Quote
  #8 (permalink)  
Old 03-22-2010, 12:58 PM
Member
 
Join Date: Mar 2010
Posts: 8
Rep Power: 0
jttslg is on a distinguished road
Default
it is however running in bluej but i wanted to try it in the command.exe while using the notepad as the editor.. my os is windows 7
Bookmark Post in Technorati
Reply With Quote
  #9 (permalink)  
Old 03-22-2010, 01:09 PM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 9,394
Rep Power: 14
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Default
Are you sure that you've set the class path properly?
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
Someone helped you? their helpful post.

Forums FAQ|Use CODE Tags|How To Ask Questions The Smart Way|The Java Tutorials|Glossary for Java|NetBeans IDE|Sun Downloads
Bookmark Post in Technorati
Reply With Quote
  #10 (permalink)  
Old 03-22-2010, 03:19 PM
Member
 
Join Date: Mar 2010
Location: Troy Upstate New York USA (Not in New York City)
Posts: 25
Rep Power: 0
The_Sponzy_Paradox is on a distinguished road
Send a message via AIM to The_Sponzy_Paradox Send a message via Yahoo to The_Sponzy_Paradox Send a message via Skype™ to The_Sponzy_Paradox
Default
Is the class named echo not echo one two three? Then try making the class name echo1 or something like that resave and recompile with the new class name
__________________
You know that line between genius and insanity? I am told I crossed it and went around back to insanity again.
Bookmark Post in Technorati
Reply With Quote
  #11 (permalink)  
Old 03-22-2010, 05:12 PM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 9,394
Rep Power: 14
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Default
Originally Posted by The_Sponzy_Paradox View Post
Is the class named echo not echo one two three? Then try making the class name echo1 or something like that resave and recompile with the new class name
No, file may save as echo.java, not Echo.java and the parameters have nothing to do with that. As I said earlier it couldn't be relate to classpath.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
Someone helped you? their helpful post.

Forums FAQ|Use CODE Tags|How To Ask Questions The Smart Way|The Java Tutorials|Glossary for Java|NetBeans IDE|Sun Downloads
Bookmark Post in Technorati
Reply With Quote
  #12 (permalink)  
Old 03-22-2010, 05:54 PM
Member
 
Join Date: Mar 2010
Posts: 8
Rep Power: 0
jttslg is on a distinguished road
Default
how do i know that classpath is the problem. it is compiling all right. when i give the arguments it shows the errors
Bookmark Post in Technorati
Reply With Quote
  #13 (permalink)  
Old 03-22-2010, 06:51 PM
Member
 
Join Date: Mar 2010
Location: Troy Upstate New York USA (Not in New York City)
Posts: 25
Rep Power: 0
The_Sponzy_Paradox is on a distinguished road
Send a message via AIM to The_Sponzy_Paradox Send a message via Yahoo to The_Sponzy_Paradox Send a message via Skype™ to The_Sponzy_Paradox
Default
c:\users\jtt\documents> java Echo one two three
Exception in thread "main" java.lang.NoClassDefFoundError: Echo
Caused by :java.lang.ClassNotFoundException: Echo

How to tell is you read the error. An exception is a problem a program cannot answer. Thus we have there is a problem in the main thread, java.lang.NoClassDefFoundError: Echo is just that there is a problem with the class Echo
__________________
You know that line between genius and insanity? I am told I crossed it and went around back to insanity again.
Bookmark Post in Technorati
Reply With Quote
  #14 (permalink)  
Old 03-22-2010, 07:29 PM
Member
 
Join Date: Mar 2010
Location: Troy Upstate New York USA (Not in New York City)
Posts: 25
Rep Power: 0
The_Sponzy_Paradox is on a distinguished road
Send a message via AIM to The_Sponzy_Paradox Send a message via Yahoo to The_Sponzy_Paradox Send a message via Skype™ to The_Sponzy_Paradox
Default
Originally Posted by Eranga View Post
No, file may save as echo.java, not Echo.java and the parameters have nothing to do with that. As I said earlier it couldn't be relate to classpath.
Perhaps but you can never be completely certain till you try. Retype everything in a new file generated in notepad. recompile and try again. I have encountered similar problems in school and that was the fix to most of them. And exceptions rarely lie
__________________
You know that line between genius and insanity? I am told I crossed it and went around back to insanity again.
Bookmark Post in Technorati
Reply With Quote
  #15 (permalink)  
Old 03-22-2010, 11:16 PM
Senior Member
 
Join Date: Feb 2009
Posts: 661
Rep Power: 2
pbrockway2 is on a distinguished road
Default
Originally Posted by The_Sponzy_Paradox View Post
Perhaps but you can never be completely certain till you try. Retype everything in a new file generated in notepad. recompile and try again. I have encountered similar problems in school and that was the fix to most of them. And exceptions rarely lie
Actually you can be completely certain that there is no problem with the classpath by using the approach I suggested in #4. (which is why I suggested that approach.)

The OP's response: "i tried the given suggestions but the error remains the same.." is unconvincing without a cut/paste and post from the command line. It would be good to include the output from the "dir" command as well so that we can verify that the precondition of #4 is met. (ie that the command is issued from the directory containing the file Echo.class)
Bookmark Post in Technorati
Reply With Quote
  #16 (permalink)  
Old 03-23-2010, 02:28 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 9,394
Rep Power: 14
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Default
Originally Posted by The_Sponzy_Paradox View Post
Perhaps but you can never be completely certain till you try. Retype everything in a new file generated in notepad. recompile and try again. I have encountered similar problems in school and that was the fix to most of them. And exceptions rarely lie
I don't think recoding is not a good solution, actually not a good practice. If it's a huge Java class, then you are going to retype them? How the errors can be avoid/tackle by retyping the code.

And as far as I feel, Java exceptions not pointed incorrect stuff. If you comes with an exception (compile/run-time) definitely there is an error in the code.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
Someone helped you? their helpful post.

Forums FAQ|Use CODE Tags|How To Ask Questions The Smart Way|The Java Tutorials|Glossary for Java|NetBeans IDE|Sun Downloads
Bookmark Post in Technorati
Reply With Quote
  #17 (permalink)  
Old 03-23-2010, 02:35 AM
Member
 
Join Date: Mar 2010
Location: Troy Upstate New York USA (Not in New York City)
Posts: 25
Rep Power: 0
The_Sponzy_Paradox is on a distinguished road
Send a message via AIM to The_Sponzy_Paradox Send a message via Yahoo to The_Sponzy_Paradox Send a message via Skype™ to The_Sponzy_Paradox
Default
Yeah, we would cut/copy as needed usually did the trick till the networking people fixed eclipse. Just an idea, I always did fine on my personal projects with either textpad or emacs and konsol shell.
__________________
You know that line between genius and insanity? I am told I crossed it and went around back to insanity again.
Bookmark Post in Technorati
Reply With Quote
  #18 (permalink)  
Old 03-23-2010, 02:39 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 9,394
Rep Power: 14
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Default
Unless it's fix the problem somehow it's fine. But that couldn't be because of the copy-paste. There is no magic in coding in any language.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
Someone helped you? their helpful post.

Forums FAQ|Use CODE Tags|How To Ask Questions The Smart Way|The Java Tutorials|Glossary for Java|NetBeans IDE|Sun Downloads
Bookmark Post in Technorati
Reply With Quote
  #19 (permalink)  
Old 03-23-2010, 12:05 PM
Member
 
Join Date: Mar 2010
Posts: 8
Rep Power: 0
jttslg is on a distinguished road
Default
can there be an error in the coding when it is working correctly on blue but not in the command.exe
Bookmark Post in Technorati
Reply With Quote
  #20 (permalink)  
Old 03-23-2010, 12:06 PM
Member
 
Join Date: Mar 2010
Posts: 8
Rep Power: 0
jttslg is on a distinguished road
Default
on blue j environment
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Command-Line Arguments mustachMan New To Java 5 02-26-2010 03:13 AM
Command Line Arguments Nakira NetBeans 10 02-04-2010 03:45 PM
[SOLVED] arguments in command-line girlet18 New To Java 2 01-21-2010 02:05 PM
Command line arguments help may88 New To Java 8 12-08-2009 01:20 PM
Multiple Command Line Arguments turnergirl24 New To Java 4 12-04-2009 09:36 PM


Java Forums is supported by the best jsp hosting.

All times are GMT +2. The time now is 09:15 PM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org