7 Replies - 1083 Views - Last Post: 29 April 2009 - 09:36 PM Rate Topic: -----

#1 MrMitra  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 46
  • Joined: 14-June 07

Help with Command Line Arguments

Posted 29 April 2009 - 06:53 PM

I am learning command line arguments I must be missing something because I cannot get them to work. Here is the simple program I am using to test it and get comfortable with it:

public class CommandTest {

	public static void main(String[] args) {
		
		for (int index = 0; index < args.length; index++)
			System.out.println(args[index]);
	}

}



then I go into the console and this happens:

Quote

C:\>java CommandTest Hi There
Exception in thread "main" java.lang.NoClassDefFoundError: CommandTest
Caused by: java.lang.ClassNotFoundException: CommandTest
at ... (bunch of java.lang, java.net places)


I am sure I am doing something simple and stupid wrong my book and the online stuff I've seen seems to be very brief and doesn't really have troubleshooting. Quick help is greatly appreciated!

Is This A Good Question/Topic? 0
  • +

Replies To: Help with Command Line Arguments

#2 mostyfriedman  Icon User is offline

  • The Algorithmi
  • member icon

Reputation: 727
  • View blog
  • Posts: 4,473
  • Joined: 24-October 08

Re: Help with Command Line Arguments

Posted 29 April 2009 - 07:25 PM

did you compile first before you running it??

make sure to compile first by

javac CommandTest.java


and then you can run it the same way you have done
Was This Post Helpful? 1
  • +
  • -

#3 MrMitra  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 46
  • Joined: 14-June 07

Re: Help with Command Line Arguments

Posted 29 April 2009 - 09:07 PM

That was it. I couldn't find the compile button off the bat in Eclipse, I thought I had already compiled it. Thanks for the help, I knew it was something simple.
Was This Post Helpful? 0
  • +
  • -

#4 webmin  Icon User is offline

  • D.I.C Regular

Reputation: 4
  • View blog
  • Posts: 256
  • Joined: 21-May 08

Re: Help with Command Line Arguments

Posted 29 April 2009 - 09:08 PM

It depends on what compiler you are using, but yes it sounds like you need to compile your program first. I know that in JCreator you go to Build -> Build File, or you can use Alt + b, then press f and that will compile it for you. Hope this helps
Was This Post Helpful? 0
  • +
  • -

#5 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8332
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Help with Command Line Arguments

Posted 29 April 2009 - 09:14 PM

View Postwebmin, on 29 Apr, 2009 - 08:08 PM, said:

It depends on what compiler you are using, but yes it sounds like you need to compile your program first. I know that in JCreator you go to Build -> Build File, or you can use Alt + b, then press f and that will compile it for you. Hope this helps

There is only one compiler Java JDK 1.xxx
What you are talking about are IDE that call this compiler on a way or on another
Don't get the multiple newbies here to get confused:
- a compiler is a compiler
- an IDE is an Editor that will eventually calls the same compiler
Was This Post Helpful? 0
  • +
  • -

#6 webmin  Icon User is offline

  • D.I.C Regular

Reputation: 4
  • View blog
  • Posts: 256
  • Joined: 21-May 08

Re: Help with Command Line Arguments

Posted 29 April 2009 - 09:15 PM

I remember that, sorry won't happen again.
Was This Post Helpful? 0
  • +
  • -

#7 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8332
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Help with Command Line Arguments

Posted 29 April 2009 - 09:28 PM

View Postwebmin, on 29 Apr, 2009 - 08:15 PM, said:

I remember that, sorry won't happen again.

Don't worry Webmin
this happens more often that you can even think about it
"I am using JCreator as compiler" or I am using "Eclipse as compiler".... it all ends up into Sun Java SDK
but newbies really have problem to distinguish IDE and compiler
we has dozen of discussion about that... as far as I am concerned newbies should go with Notepad and javac at the command prompt
their are a lotof discussions about that in this forum... the main question being "what is the best pedagogic approach" ?

I think people must learn the "hard way"
Others recommend IDE day 1
this is an endless discussion
I did my first 2 years of Java with UltraEdit and > javac at the consol prompt
I think this is the way to go

We have discussions here among the most posters... what about IDE generated code

A user comes and says: "My API does not work"
you look at it... 10,000 lines of code generated by Netbeans (or whatever API)
many times we have to respond to these DIC: "Sorry we can fix human beings generated API but not Netbeans generated code of thousands of lines using Layout we never heard of"

Beside that: Welcome at DIC :^:
Was This Post Helpful? 0
  • +
  • -

#8 webmin  Icon User is offline

  • D.I.C Regular

Reputation: 4
  • View blog
  • Posts: 256
  • Joined: 21-May 08

Re: Help with Command Line Arguments

Posted 29 April 2009 - 09:36 PM

Yeah I remember learning the javac, and all the typing got annoying so eventually I started creating batch files for each project so whenever I wanted to compile and run my program I would just click on my batch file and it ran (That is if there were no errors). I stayed away from Netbeans as long as I could, mostly working through JCreator. Now I only work with Netbeans if I need granular control over GUI programming that I can't get with JCreator. But yeah command line environment is very important and should be taught before you ever start any type of programming language.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1