View Single Post
Old Dec 26th, 2007, 1:03 AM   #3
Energizer
Newbie
 
Join Date: Dec 2007
Posts: 4
Rep Power: 0 Energizer is on a distinguished road
Re: PLEASE PLEASE help up since 1 trying to fix this simple yet stupid problem....

Quote:
Originally Posted by mrynit View Post
One man's rubbush is a nother man's treasure. Errors tell you what is wrong and hopefully where by giving line numbers.

Sounds like your code is bad.

No, I cannot. I see none of your code and subsequently I cannont help you.

Here is a working example of accepting command line arguments. It uses Java 5 Enhanced For Loop to iterate the array of strings.

java Syntax (Toggle Plain Text)
  1. import java.io.*;
  2.  
  3. public class PrintArgs
  4. {
  5. public static void main(String[] args)
  6. {
  7. System.out.println("This is stuff you entered: \n");
  8.  
  9. for(String myString: args)
  10. {
  11. System.out.println(myString);
  12. }
  13.  
  14. System.out.println("\nEnd of stuff you entered.");
  15. }
  16. }

C:\>javac PrintArgs.java

C:\>java PrintArgs arg0 arg1 arg2 yar-harg
This is stuff you entered:

arg0
arg1
arg2
yar-harg

End of stuff you entered.

C:\>
thanks for the reply mrynit.
This is the error I get after I copy and past your code into a new netbeans class

init:
deps-jar:
Compiling 1 source file to C:\Users\admin\Documents\NetBeansProjects\JavaNode\build\classes
javac: invalid flag: 1
Usage: javac <options> <source files>
use -help for a list of possible options
BUILD FAILED (total time: 0 seconds

f1 help doesn't do much.

here is code I wrote and tried to run:

public class NewClass {
public static void main (String[]args)

{System.out.println("hi" + args[0]);}

}

and I get this error:

init:
deps-jar:
Compiling 1 source file to C:\Users\azhari\Documents\NetBeansProjects\JavaNode\build\classes
javac: invalid flag: 1
Usage: javac <options> <source files>
use -help for a list of possible options
BUILD FAILED (total time: 0 seconds)


do you know how to pass arguments via any other enviornment e.g. j-creater, eclise etc?
Energizer is offline   Reply With Quote