• NetBeans IDE 7.0 argument problem (HELP PLEASE)
    16 replies, posted
I am learning Java by a book and when the book tells me to use arguments in the Project Properties, it gives me an error. I've tried downloading the right code, searching for fixes, but it seems that no one knows how to do it. This problem has been bothering me for a while. Here is my basic code: [code]class BlankFiller { public static void main(String[] args) { System.out.println("The " + args[0] + " " + args[1] + " fox " + "jumped over the " + args[2] + " dog."); } }[/code] As you can see, I am using args[0], args[1], and args[2]. The code seems to be correct (checked multiple times and downloaded the correct code from the textbook's website). When I go to Run > Set Project Configuration > Customize > Run and put in this: [img]http://i.imgur.com/BDaQW.jpg[/img] It gives me this error: [code]Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0 at BlankFiller.main(BlankFiller.java:3) Java Result: 1[/code] I've tried putting the argumentss as args[1] args[2] args[3] and multiple other ways, but they give me a similar error, only values change. Any help would be very awesome.
I'm not familiar with NetBeans, so I can't help you there. Your code is fine though; the solution will be somewhere in the run configuration.
Do you have it in a package? If so that needs to be specified. Otherwise I don't see any problem.
do you have to put a , after each argument? instead of what your doing try something like: [code] public static void main(String[] args) { for(int i = 0; i < getLength(args); i++) System.out.println("Array Item: " + i + " = " + args[i]"); } [/code]
Works for me in Eclipse, so the problem is in your IDE. [CODE]public class Hello { public static void main(String[] args) { System.out.println(args.length); System.out.println("The " + args[0] + " " + args[1] + " fox " + "jumped over the " + args[2] + " dog."); } } [/CODE] Args: quite awesome stuff Output: [CODE]3 The quite awesome fox jumped over the stuff dog. [/CODE]
Yeah, the whole problem is with NetBeans. I was hoping someone knew NetBeans really well and told me what the problem is. [QUOTE=ryan1271;32582272]Do you have it in a package? If so that needs to be specified. Otherwise I don't see any problem.[/QUOTE] I'm using the default package. Where do I specify it?
What happens when you click browse-button after main class-textbox?
[QUOTE=Simspelaaja;32590385]What happens when you click browse-button after main class-textbox?[/QUOTE]It sends me to the "Browse Main Classes", and I get to choose which class' properties I want to edit. Doesn't seem like the problem is there.
[IMG]http://filesmelt.com/dl/Screenshot-115.png[/IMG] My code [CODE]/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package blankfiller; /** * * @author phreebird */ public class Main { /** * @param args the command line arguments */ public static void main(String[] args) { System.out.println("The " + args[0] + " " + args[1] + " fox " + "jumped over the " + args[2] + " dog."); } } [/CODE]
[QUOTE=Phreebird;32591006]Stuff[/QUOTE]I do not see how this would help me in any way, because I cannot understand what you are trying to say. I followed the book. It said to create a New File, name it BlankFiller, and put in that code. I reviewed the code, copied it from the official website, too, and followed the instructions on how to edit the arguments. Nothing worked.
"Standard projects use a ide generated build script" Netbeans has its own little weird way of Java. Make a new project, Then just copy and paste your code under the main method, Do the args and it should work. Also, Did you book tell you to use netbeans?
[QUOTE=Phreebird;32591706]"Standard projects use a ide generated build script" Netbeans has its own little weird way of Java. Make a new project, Then just copy and paste your code under the main method, Do the args and it should work. Also, Did you book tell you to use netbeans?[/QUOTE]I tried doing that, and it still gives me the same error. And yes, the book told me to use NetBeans, and where to download it, etc.
Can you show us ALL of the code and the project name? And what book are you using?
i now what book ure usingi had this 2. i cant remember exact so bear with me, 1 run > set main project > choose ures 2 run > set project configertion > new, name it, then u must enter classname, so BlankFiller, n put ure argus in 3 run >set project configertion (then click ure 1 u made 4 run > run main project basicly u gotts make this class mainproject and create new run config
[QUOTE=IZAC;32615682]i now what book ure usingi had this 2. i cant remember exact so bear with me, 1 run > set main project > choose ures 2 run > set project configertion > new, name it, then u must enter classname, so BlankFiller, n put ure argus in 3 run >set project configertion (then click ure 1 u made 4 run > run main project basicly u gotts make this class mainproject and create new run config[/QUOTE]It's a little bit hard to understand you, but I've done that before and it worked fine. The thing is, it's telling me to run the file itself (F6) and not the project as a whole. Maybe that was the problem and the book is confusing it? EVERYONE - TRY DOING THE SAME CODE AND ARGS BUT USE [B]"RUN FILE"[/B], NOT MAIN PROJECT.
yeh i thnk prob is cos it only send args to main class, but book shld specify this, u can also set it r-clickng on project node on left bar, tbook shuld mention this cos other have probl too
[QUOTE=IZAC;32622819]yeh i thnk prob is cos it only send args to main class, but book shld specify this, u can also set it r-clickng on project node on left bar, tbook shuld mention this cos other have probl too[/QUOTE]Jesus, I cannot understand a word you are trying to say.
Sorry, you need to Log In to post a reply to this thread.