Troubleshooting Java Arguments: How to Fix Common Errors

  • Context: Java 
  • Thread starter Thread starter UltimateSomni
  • Start date Start date
  • Tags Tags
    Java
Click For Summary

Discussion Overview

The discussion revolves around troubleshooting issues related to passing command-line arguments in a Java program using the NetBeans IDE. Participants explore various potential causes for the errors encountered and suggest different approaches to resolve the problem.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Exploratory

Main Points Raised

  • One participant reports receiving an error when attempting to run a Java program with command-line arguments and questions what went wrong.
  • Another participant suggests that the IDE may not be configured correctly and recommends running the program from the command line instead.
  • Some participants emphasize the importance of being in the correct directory where the compiled .class file is located to run the program successfully.
  • There are discussions about the command-line interface and the necessity of using the correct commands to change directories and run the Java program.
  • Several participants express uncertainty about the IDE's handling of command-line arguments, with some suggesting that it may not be passing them correctly.
  • One participant shares their Java code and the expected output, indicating that the program behaves as intended when run from the command line.
  • There are inquiries about finding configuration settings in NetBeans, such as the VM Options box and the fully-qualified name for the Main Class.
  • Some participants recommend alternative IDEs, such as IntelliJ, while others caution against assuming the IDE is at fault without further investigation.

Areas of Agreement / Disagreement

Participants generally agree that the issue may stem from the IDE's configuration, but there is no consensus on the exact cause or solution. Multiple competing views on how to troubleshoot the problem remain present throughout the discussion.

Contextual Notes

Participants mention potential limitations in the NetBeans IDE regarding command-line argument handling, but specific details about the configuration or settings that may be causing the issue are not resolved.

Who May Find This Useful

This discussion may be useful for Java programmers encountering issues with command-line arguments in the NetBeans IDE, as well as those interested in troubleshooting IDE configurations.

Technology news on Phys.org
I'd say your IDE is screwing with your mind... It looks like you have enter arguments correctly, are you sure you are running that configuration?

Can you try running the class file from a command line?

java BlankFiller arg0 arg1 arg2
 
schip666! said:
I'd say your IDE is screwing with your mind... It looks like you have enter arguments correctly, are you sure you are running that configuration?

Can you try running the class file from a command line?

java BlankFiller arg0 arg1 arg2

http://i52.tinypic.com/20rttec.jpg
 
UltimateSomni said:
You have to run that from the directory where the compiled BlankFiller.class file is located. If it didn't compile, there will only be a BlankFiller.java file.
 
Borg said:
You have to run that from the directory where the compiled BlankFiller.class file is located. If it didn't compile, there will only be a BlankFiller.java file.

What?

Does anyone know why this isn't working? Did I input the arguments wrong?
 
UltimateSomni said:
What?

Does anyone know why this isn't working? Did I input the arguments wrong?
When you compile a java file, a .class file is created. That is what actually gets used when you run a java program. NetBeans probably created it but you have to be in that directory to run schip666!'s command line test. You ran your test from c:/users/fred. If BlankFiller.class isn't there, the test will fail with the reason shown on your link.
 
Time to learn about CLASSPATH...

Look for BlankFiller.class.
In your command window, cd to that directory.
Then try: java -classpath . BlankFiller 1 2 3
 
I found BlankFiller.class
what does "cd to that directory" mean?
 
type: cd that-directory

god I love the GUI universe.

most likely there's something else wrong, but it is handy to know your way around a command line interface if you plan to program for anything but the web.
 
  • #10
ugh I have to leave but still no idea what you're trying to say
 
  • #11
UltimateSomni said:
ugh I have to leave but still no idea what you're trying to say
cd is the dos command for "change directory". Let's say that your file is in a directory C:\Users\Fred\NetBeans directory (substitute what you found). Before you run the java command that failed, type this:

cd C:\Users\Fred\NetBeans

Note that dos is a really old languange and doesn't know about spaces. So if your directory had spaces anywhere, you have to put quotes around it like this:

cd "C:\Users\Fred\NetBeans"

Once you change to the correct directory, you can run your java test on the class file.
 
  • #13
UltimateSomni said:
http://i51.tinypic.com/316qgyc.jpg
Well, maybe that's some progress.
My office blocks lots of web sites and the tinypic site that you're using is one of them. I can't help until late this afternoon unless you explain what happened.
 
  • #14
Command promt says the "1 2 dog jumped over the 3 fox"
And "the arg1 arg2 dog jumped over the 3 dog"
 
  • #15
UltimateSomni said:
Command promt says the "1 2 dog jumped over the 3 fox"
And "the arg1 arg2 dog jumped over the 3 dog"
Could you also paste the content of your main method in code tags?
Also, what did you type into the command prompt?
 
  • #16
Can you see Google Docs? http://tinyurl.com/OrangeYellowArguments

And I did this exactly how the book told me to type it in:

class BlankFiller {
public static void main(String[] args) {
System.out.println("The " +args[0]
+ " " + args[1] + " fox "
+ "jumped over the "
+ args[2] + " dog."
);
}
}
 
Last edited by a moderator:
  • #17
UltimateSomni said:
Command promt says the "1 2 dog jumped over the 3 fox"
And "the arg1 arg2 dog jumped over the 3 dog"

That appears to be what you should expect to get. The argN's are put into the places that had arg[n] in the your original program code (IIRC...). Thus your netBums IDE is screwing with you somehow.

So... first, you may not be using the IDE correctly, but from casual examination of the screen shots you posted it appears that you are doing things right; so... second, NET Beans is a networked java environment where programs are unlikely to have access to command line arguments anyway, thus they may have never implemented it right to start with.
 
  • #18
schip666! said:
That appears to be what you should expect to get. The argN's are put into the places that had arg[n] in the your original program code (IIRC...). Thus your netBums IDE is screwing with you somehow.

So... first, you may not be using the IDE correctly, but from casual examination of the screen shots you posted it appears that you are doing things right; so... second, NET Beans is a networked java environment where programs are unlikely to have access to command line arguments anyway, thus they may have never implemented it right to start with.

So my best bet is that this isn't my fault and I should wait for an update that fixes this issue?

The author is using Netbeans 6.5, I am using 7 anyway.
 
  • #19
Try typing this in your command line:

java BlankFiller quick brown lazy

What comes back?
 
  • #20
Borg said:
Try typing this in your command line:

java BlankFiller quick brown lazy

What comes back?
https://docs.google.com/drawings/d/1ffRd24ddIKQtGcr6DcxKFRdcS98Z_NilFnSaeSC4pE0/edit?hl=en_US

That one I get what I should get, but I can't get the arguments I type into work
 
Last edited by a moderator:
  • #21
Then it seems that the NetBeans IDE is not passing the command-line arguments to your program correctly, but if you run you program from the command-line, things are as they should be.
 
  • #22
So you recommend using an different IDE?

God damn you have tons of posts
 
  • #23
UltimateSomni said:
So you recommend using an different IDE?
Not if that's the only problem.

Is there a readme file for this IDE? That's where they usually list bugs that are known issues.
 
  • #24
UltimateSomni said:
So you recommend using an different IDE?
The IDE probably isn't set up right. From the other screenshots that you posted, it is working properly in dos.

Unfortunately, I haven't used NetBeans to figure out why it doesn't recognize the variables. From what I read on the NetBeans site for http://netbeans.org/kb/docs/java/project-setup.html#deploy-jvm" and verify that you've done everything the way that they've instructed?
 
Last edited by a moderator:
  • #25
Am I suppose to type something into the VM Options box?

So I'm suppose to type in the fully-qualified name in the Main Class field (for example, org.myCompany.myLib.MyLibClass). How do I find that?
 
Last edited:
  • #26
How would I find a readme file?
 
  • #27
UltimateSomni said:
How would I find a readme file?
Readme files are usually located in the top level directory where the program was installed. If you're using XP, it's probably somewhere in the Program Files directory.
 
  • #28
UltimateSomni said:
Am I suppose to type something into the VM Options box?

So I'm suppose to type in the fully-qualified name in the Main Class field (for example, org.myCompany.myLib.MyLibClass). How do I find that?
I'm sorry but, I really am not familiar with how to set up NetBeans. Unless someone else here knows, your best bet might be to ask configuration questions on the http://forums.netbeans.org/netbeans-users.html".
 
Last edited by a moderator:
  • #29
So I asked on Netbeans, but the message board looks slow

Is there another free IDE you guys recommend?
 
  • #30
UltimateSomni said:
So I asked on Netbeans, but the message board looks slow

Is there another free IDE you guys recommend?
I use IntelliJ and know that one very well. The current pay version is 10.5 but, I think that version 8 is free.
 

Similar threads

  • · Replies 3 ·
Replies
3
Views
7K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 3 ·
Replies
3
Views
4K
Replies
7
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 7 ·
Replies
7
Views
4K
Replies
17
Views
6K
Replies
3
Views
3K