Page 1 of 2 12 LastLast
Results 1 to 20 of 24
  1. #1
    jttslg is offline Member
    Join Date
    Mar 2010
    Posts
    26
    Rep Power
    0

    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

  2. #2
    j2me64's Avatar
    j2me64 is offline Senior Member
    Join Date
    Sep 2009
    Location
    Zurich, Switzerland
    Posts
    962
    Rep Power
    6

    Default

    is Echo.java compiled with javac without errors? looking at the erros i don't believe. so post your Echo.java code here.

  3. #3
    jttslg is offline Member
    Join Date
    Mar 2010
    Posts
    26
    Rep Power
    0

    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]);
    }
    }

  4. #4
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    Go to the directory (folder) containing Echo.class and run the program with the following command:

    Java Code:
    java -cp . Echo


    The "-cp" tells the java executable where to look for classes. And the dot means "here, in this directory".

  5. #5
    nigamsir is offline Member
    Join Date
    Mar 2010
    Posts
    11
    Rep Power
    0

    Default cmd line arg

    1. install jdk
    2. install netbeans
    3. set command line arguments from project properties

  6. #6
    Join Date
    Mar 2010
    Location
    Troy Upstate New York USA (Not in New York City)
    Posts
    25
    Rep Power
    0

    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.

  7. #7
    jttslg is offline Member
    Join Date
    Mar 2010
    Posts
    26
    Rep Power
    0

    Default command line

    i tried the given suggestions but the error remains the same.... i am using jdk1.6.0_17

  8. #8
    jttslg is offline Member
    Join Date
    Mar 2010
    Posts
    26
    Rep Power
    0

    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

  9. #9
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

  10. #10
    Join Date
    Mar 2010
    Location
    Troy Upstate New York USA (Not in New York City)
    Posts
    25
    Rep Power
    0

    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.

  11. #11
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote 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.

  12. #12
    jttslg is offline Member
    Join Date
    Mar 2010
    Posts
    26
    Rep Power
    0

    Default

    how do i know that classpath is the problem. it is compiling all right. when i give the arguments it shows the errors

  13. #13
    Join Date
    Mar 2010
    Location
    Troy Upstate New York USA (Not in New York City)
    Posts
    25
    Rep Power
    0

    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.

  14. #14
    Join Date
    Mar 2010
    Location
    Troy Upstate New York USA (Not in New York City)
    Posts
    25
    Rep Power
    0

    Default

    Quote 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.

  15. #15
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    Quote 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)

  16. #16
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote 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.

  17. #17
    Join Date
    Mar 2010
    Location
    Troy Upstate New York USA (Not in New York City)
    Posts
    25
    Rep Power
    0

    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.

  18. #18
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    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.

  19. #19
    jttslg is offline Member
    Join Date
    Mar 2010
    Posts
    26
    Rep Power
    0

    Default

    can there be an error in the coding when it is working correctly on blue but not in the command.exe

  20. #20
    jttslg is offline Member
    Join Date
    Mar 2010
    Posts
    26
    Rep Power
    0

Page 1 of 2 12 LastLast

Similar Threads

  1. Command-Line Arguments
    By mustachMan in forum New To Java
    Replies: 5
    Last Post: 02-26-2010, 03:13 AM
  2. Command Line Arguments
    By Nakira in forum NetBeans
    Replies: 10
    Last Post: 02-04-2010, 03:45 PM
  3. arguments in command-line
    By girlet18 in forum New To Java
    Replies: 2
    Last Post: 01-21-2010, 02:05 PM
  4. Command line arguments help
    By may88 in forum New To Java
    Replies: 8
    Last Post: 12-08-2009, 01:20 PM
  5. Multiple Command Line Arguments
    By turnergirl24 in forum New To Java
    Replies: 4
    Last Post: 12-04-2009, 09:36 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •