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.

  • #31
I wouldn't assume it's Netbeans and not something you did (or didn't do). I would be pretty surprised if they've managed to break such simple and basic functionality. You can try Eclipse if you like. I tend to use it for Java and Python. But Netbeans is quite good.

While I'm thinking of it, why don't you just copy/paste messages and such into the forums rather than making us look at screenshots and such? Because I'll tell you that I didn't look at them. If you want me to look at them, paste them into the forum. Taking screenshots of text is, in most cases, really pointless.

Anyways, I took some time out to make a quick test project in my Netbeans 6.9.1 (good to know there's a 7 out, I'll try that out later). I wrote out all my steps one-by-one. It works fine for me. Here's the steps:

1. Start Netbeans

2. In the menu bar, select File->New Project.
Make sure these are selected in the dialog box:
Categories: Java
Projects: Java Application
Hit Next
Fill in the Project Name field with: ArgTest
Take note of where it is putting your project in the Project Location and
Project Folder fields.
Hit Finish

3. Edit the Main.java file and add this to the main function's body (you can remove the comment in there, of course):
Code:
        for (String arg : args) {
            System.out.println(arg);
        }

4. Click "Build Main Project" icon in toolbar (a hammer). Wait for it to finish.

5. In Run menu, select "Set Project Configuration->Customize...".
In the Categories sidebar, "Run" should be selected. In the "Arguments"
text edit, enter test arguments such as (without the quotes):

"arg1 arg2 arg3 arg4"

Click Ok.

6. Click the "Run Main Project" icon in the toolbar (green arrow facing
right). In the output pane, you should see the arguments you passed in.
I see this:
Code:
run:
arg1
arg2
arg3
arg4
BUILD SUCCESSFUL (total time: 1 second)

If you get a different result here, I'm rather surprised.

I'll probably install the latest version of NetBeans soon, so I'll check it out again in version 7 later.

EDIT: I installed NetBeans 7 (in Linux) and ran the project I created, and the arguments came through perfectly. I can try remaking the project from scratch in 7.0 if you like. But argument passing is not broken in NetBeans 7.0, at least in general. Could be it's a Windows only bug, but I really, seriously doubt it.
 
Last edited:
Technology news on Phys.org
  • #32
I've got one possibility why it might not see your arguments.

In the project directory, there's a subdirectory called nbproject. It has a subdirectory called private. In that directory, there's the file that should contain your arguments called private.properties.

My private.properties contains this line right at the start:

application.args=arg1 arg2 arg3 arg4

Make sure you have something like that in yours.

If it's not picking it up, it may have been overridden by something in your build.xml file (which is right in the root of your project's directory). Make sure you don't have a line like this:

<target name="-init-private" depends="-pre-init">

From what Some Guy On The Internet(tm) says, that causes the one in private.properties to be ignored. I don't have anything but the opening XML tag, a project element that wraps everything, and a description and an import tag inside.

Not 100% sure how to fix it (if that's it), but he says you need to put a line in your project.properties file (which is in the nbproject subdirectory).

I would try two things (keeping a backup of any file modified so you can put it back in place if anything breaks)). First, removing that offending line from the build.xml, if present. I would try that first. Not sure how it gets in there, or why, but perhaps removing it will fix it.

Otherwise, perhaps adding the args parameter that's in private.properties to project.properties will fix it.

So, in my case (with the example in the previous post), I would try adding this line from private.properties to project.properties:

application.args=arg1 arg2 arg3 arg4

Let me know if any of that works. Also, I'll repeat because it's important. Make backups of any file you edit so you can copy it back in place if it messes things up. This is just info from some random person on the 'net that I found. I haven't tried it out (for one, I don't have the problem you're having).
 
  • #33
Yes, so I click Run Main Project instead of Run File. It all works now.
 
  • #34
Grep said:
I wouldn't assume it's Netbeans and not something you did (or didn't do). I would be pretty surprised if they've managed to break such simple and basic functionality. You can try Eclipse if you like. I tend to use it for Java and Python. But Netbeans is quite good.

While I'm thinking of it, why don't you just copy/paste messages and such into the forums rather than making us look at screenshots and such? Because I'll tell you that I didn't look at them. If you want me to look at them, paste them into the forum. Taking screenshots of text is, in most cases, really pointless.

Anyways, I took some time out to make a quick test project in my Netbeans 6.9.1 (good to know there's a 7 out, I'll try that out later). I wrote out all my steps one-by-one. It works fine for me. Here's the steps:

1. Start Netbeans

2. In the menu bar, select File->New Project.
Make sure these are selected in the dialog box:
Categories: Java
Projects: Java Application
Hit Next
Fill in the Project Name field with: ArgTest
Take note of where it is putting your project in the Project Location and
Project Folder fields.
Hit Finish

3. Edit the Main.java file and add this to the main function's body (you can remove the comment in there, of course):
Code:
        for (String arg : args) {
            System.out.println(arg);
        }

4. Click "Build Main Project" icon in toolbar (a hammer). Wait for it to finish.

5. In Run menu, select "Set Project Configuration->Customize...".
In the Categories sidebar, "Run" should be selected. In the "Arguments"
text edit, enter test arguments such as (without the quotes):

"arg1 arg2 arg3 arg4"

Click Ok.

6. Click the "Run Main Project" icon in the toolbar (green arrow facing
right). In the output pane, you should see the arguments you passed in.
I see this:
Code:
run:
arg1
arg2
arg3
arg4
BUILD SUCCESSFUL (total time: 1 second)

If you get a different result here, I'm rather surprised.

I'll probably install the latest version of NetBeans soon, so I'll check it out again in version 7 later.

EDIT: I installed NetBeans 7 (in Linux) and ran the project I created, and the arguments came through perfectly. I can try remaking the project from scratch in 7.0 if you like. But argument passing is not broken in NetBeans 7.0, at least in general. Could be it's a Windows only bug, but I really, seriously doubt it.

Very nice!
 
  • #35
UltimateSomni said:
Yes, so I click Run Main Project instead of Run File. It all works now.

Excellent! Now it makes sense why it wasn't working.

Mark44 said:
Very nice!

Thanks, Mark!
 
  • #36
UltimateSomni said:
Yes, so I click Run Main Project instead of Run File. It all works now.
Hooray! :smile:
 

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