Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   Java (http://www.programmingforums.org/forum17.html)
-   -   PLEASE PLEASE help up since 1 trying to fix this simple yet stupid problem.... (http://www.programmingforums.org/showthread.php?t=14808)

Energizer Dec 25th, 2007 10:29 PM

PLEASE PLEASE help up since 1 trying to fix this simple yet stupid problem....
 
Good morning everyone - Just joined the site!:icon_mrgreen:

I really need help/advice/instuctions:icon_confused:....To cut a long story short I have created a few java programs via net beans. Now they compile and run fine via net beans, but I cant find out how to pass arguments into it.

This is usually done via windows separate command line, i.e:

c: javac myCode.java //to compile it

c: java myCode somethingIwantTopassIntoTheCode //to run it with a parameter


it compiles on the command line but when I try to run it I get an error:

Exception in thread "main" java.lang.NoClassDefFoundError: myCode

along with some other rubbish.

So I cant pass arguments via the command line and cant pass arguments via netbeans. I need to do this for some uni work ASAP so If anyone knows how to fix this, or even better how to pass arguments through net bean independently It would help me soo much! As you can see I have been up all night trying to fix this, I have also searched the forums but cant seem to find a similar thread. I have also downloaded eclipse but don’t know how to pass arguments through that either: sad:

I have been told by a friend to: "To specify command line arguments, right click your project node and click properties.
Click the 'compile' tab to specify compiler arguments or click the 'run' tab to specify runtime arguments."

but I found the tabs and places to enter the arguments and entered 4 + 1 and even though I have entered the arguments it still doesn't use the arguments. I have tried this on other code which I am sure is correct, but still doesn’t work. Do I need to do some sort of application/implementation of these arguments?

If anyone knows how to pass arguments through ANY IDE PLEASE tell me how I'l download another programming environment if needs be....

thanks so much!


Energizer

mrynit Dec 26th, 2007 12:52 AM

Quote:

along with some other rubbish.
One man's rubbush is a nother man's treasure. Errors tell you what is wrong and hopefully where by giving line numbers.

Quote:

So I cant pass arguments via the command line and cant pass arguments via netbeans
Sounds like your code is bad.

Quote:

As you can see I have been up all night trying to fix this
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.

:

  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:\>


Energizer Dec 26th, 2007 2:03 AM

Re: PLEASE PLEASE help up since 1 trying to fix this simple yet stupid problem....
 
Quote:

Originally Posted by mrynit (Post 138719)
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.

:

  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?

Dameon Dec 26th, 2007 3:02 AM

Re: PLEASE PLEASE help up since 1 trying to fix this simple yet stupid problem....
 
Make sure you specified arguments for your program, not the compiler.

mrynit Dec 26th, 2007 3:41 AM

Here are some things to improve upon:

The Title for thread is not descriptive to your problem and contains repeated words in caps lock. Most people here will not read threads that have dummy titles because they know what's inside is not worth their effort. Being clear and descriptive in creases your chances of getting help.

You Did not post code and errors originally. when doing so use the code tags(the # icon). To add java syntax highlighting put =java at the end of the opening code tag before the brace. The idea is to separate your thoughts from code and errors. It also makes the post readable. This forum has been designed to handle code posting in a manner that makes reading code easier to look at rather than it being in plain text field.

When replying to some one you do not have to quote their entire message. Only quote the parts that are relevant to conversation between you and the person(s). For an example see how I quoted your post.

Please read the forum rules and suggestions. If you did you would not have seen the last paragraphs :icon_wink:

As for you question:

It looks like your IDE is not configured correctly. You should get it configured correctly before trying the parameters game. I know nothing of NetBeads and little of Eclipse. I know for both and any quality IDE you can pass parameters to the program. Consult the manual or search the IDE's homepage.

Energizer Dec 26th, 2007 4:41 AM

Re: PLEASE PLEASE help up since 1 trying to fix this simple yet stupid problem....
 
Quote:

Originally Posted by Dameon (Post 138722)
Make sure you specified arguments for your program, not the compiler.

Can you tell me how I can check this please?

Energizer Dec 26th, 2007 4:49 AM

Re: PLEASE PLEASE help up since 1 trying to fix this simple yet stupid problem....
 
Thanks mrynit,

I do apologise for not setting the right format. I would have read the forum rules though I am in such as rush to get this thing finished. Your concise words have helped, and I will endeavour to follow the right code of conduct.
I will try reading the IDE manual again, but it is difficult to know what to look for - search engine brings results of little use and sub topics are by the dozen. I think it may take hours of trail and error before I get this thing working.
If I cant not get a result from this forum can you recommend anywhere else I should try looking?

mrynit Dec 26th, 2007 2:50 PM

Re: PLEASE PLEASE help up since 1 trying to fix this simple yet stupid problem....
 
If this is for school are you required to use an IDE? If so why has not your instructor told you how to do console input?

For NetBeans http://www.google.com/search?en&q=co...ments+netbeans. The PDF looks nice. Note the search terms, google fu.

In Eclipse:

Click on the down black arrow next to the green circle with white arrow pointing right.
Click on open run dialog. Select your application on the left. Click on the Arguments tab on the right menu systm. Enter what you want into the Program arguments.


All times are GMT -5. The time now is 3:37 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC