Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Dec 25th, 2007, 10:29 PM   #1
Energizer
Newbie
 
Join Date: Dec 2007
Posts: 4
Rep Power: 0 Energizer is on a distinguished road
PLEASE PLEASE help up since 1 trying to fix this simple yet stupid problem....

Good morning everyone - Just joined the site!

I really need help/advice/instuctions....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
Energizer is offline   Reply With Quote
Old Dec 26th, 2007, 12:52 AM   #2
mrynit
Hobbyist Programmer
 
mrynit's Avatar
 
Join Date: Mar 2006
Location: WA, USA
Posts: 342
Rep Power: 3 mrynit is on a distinguished road
Send a message via AIM to mrynit Send a message via MSN to mrynit Send a message via Yahoo to mrynit Send a message via Skype™ to mrynit
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.

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:\>
__________________
i dont know much about programming but i try to help
mrynit is offline   Reply With Quote
Old Dec 26th, 2007, 2: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
Old Dec 26th, 2007, 3:02 AM   #4
Dameon
Troll
 
Dameon's Avatar
 
Join Date: Apr 2005
Location: Texas
Posts: 732
Rep Power: 4 Dameon is on a distinguished road
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.
__________________
MD5(sig) = bcef75433db02e9ad9bf81d6f7c5c270
Dameon is offline   Reply With Quote
Old Dec 26th, 2007, 3:41 AM   #5
mrynit
Hobbyist Programmer
 
mrynit's Avatar
 
Join Date: Mar 2006
Location: WA, USA
Posts: 342
Rep Power: 3 mrynit is on a distinguished road
Send a message via AIM to mrynit Send a message via MSN to mrynit Send a message via Yahoo to mrynit Send a message via Skype™ to mrynit
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

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.
__________________
i dont know much about programming but i try to help
mrynit is offline   Reply With Quote
Old Dec 26th, 2007, 4:41 AM   #6
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 Dameon View Post
Make sure you specified arguments for your program, not the compiler.
Can you tell me how I can check this please?
Energizer is offline   Reply With Quote
Old Dec 26th, 2007, 4:49 AM   #7
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....

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?
Energizer is offline   Reply With Quote
Old Dec 26th, 2007, 2:50 PM   #8
mrynit
Hobbyist Programmer
 
mrynit's Avatar
 
Join Date: Mar 2006
Location: WA, USA
Posts: 342
Rep Power: 3 mrynit is on a distinguished road
Send a message via AIM to mrynit Send a message via MSN to mrynit Send a message via Yahoo to mrynit Send a message via Skype™ to mrynit
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.
__________________
i dont know much about programming but i try to help
mrynit is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Simple blackjack script problem. Need help. jokr004 C++ 6 Feb 10th, 2006 12:44 PM
EXTREMELY simple problem d_heyzie C++ 15 Feb 3rd, 2006 12:32 AM
Simple Perl / MySQL Problem.. pls help! domquemo Perl 0 Jan 11th, 2006 5:08 AM
Problem with using DLL from simple c program. scicatur C 0 May 12th, 2005 12:19 PM
repaint() problem in very simple program dotred Java 1 Mar 17th, 2005 6:17 AM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 4:57 AM.

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