i get
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 2
at Producent.main(producent.java:605)
when i run it from bat
@start "Supply Chain Management-Producer to Queue" run Producent queue1 queue2 queue3 queue4
maybe you will se something i dont see -
public static void main(String[] args){
-
-
-
-
if (args.length < 1 || args.length > 4) {
-
System.out.println("usage: <destination> <destination> <destination> <destination>");
-
System.exit(1);
-
}else {Producent producent=new Producent(args[0],args[1],args[2],args[3]);}
-
/// producent.close();
-
-
}
-
}
-
thank you
22 40955
i get
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 2
at Producent.main(producent.java:605)
when i run it from bat
@start "Supply Chain Management-Producer to Queue" run Producent queue1 queue2 queue3 queue4
maybe you will se something i dont see -
public static void main(String[] args){
-
-
-
-
if (args.length < 1 || args.length > 4) {
-
System.out.println("usage: <destination> <destination> <destination> <destination>");
-
System.exit(1);
-
}else {Producent producent=new Producent(args[0],args[1],args[2],args[3]);}
-
/// producent.close();
-
-
}
-
}
-
thank you
The error will occur if args.length is 1, 2, or 3. Change your if condition.
i changed it to
if (args.length < 1 || args.length > 3)but stiil get the exception
i changed it to
if (args.length < 1 || args.length > 3)but stiil get the exception
You are complicating things for your self. Don't you just want to run this if you have at least 4 objects in your array.
i changed it to
if (args.length < 1 || args.length > 3)but stiil get the exception
Your else statement still tries to call args[0], 1, 2, and 3.
Just think about the following scenarios that go to your else statement: -
args.length == 1, it still tries to call args[1],2,3
-
-
args.length == 2, it still tries to call args[2],3
-
-
args.length == 3, it still tries to call args[3]
-
-
only with args.length == 4 or more is it able to call all of these...
-
You need to add else if's for each of these cases or do only when args.length > 3...
Hope this helped you out,
-blazed
.... i threw out the if
left only -
public static void main(String[] args){
-
-
-
-
-
Producent producent=new Producent(args[0],args[1],args[2],args[3]);
-
-
-
-
}
-
}
-
and i stil get the exception
thank you
.... i threw out the if
left only -
public static void main(String[] args){
-
-
-
-
-
Producent producent=new Producent(args[0],args[1],args[2],args[3]);
-
-
-
-
}
-
}
-
and i stil get the exception
thank you
Don't throw away the if. You need it to handle abnormal data.
Use the if(args.length > 3) that has been suggested.
but why it still throws the exception when i got rid of args.length ?
the exception is in thread main so i shouldn't look somewhere else for it ?
but why it still throws the exception when i got rid of args.length ?
the exception is in thread main so i shouldn't look somewhere else for it ?
Dude, refer to my above post. It's hard to be any more clear.
It doesn't have ANYTHING to do with trying to access args.length. IndexArrayOutOfBounds Exception occurs because you're trying to access an index in the array that is too high or too low (doesn't exist) or could not exist ( Out Of Bounds, get it? ) .
Listen, it's not because of args.length, args.length will always just give you the length of the array, like 1, or 2 or 3 or whatever number.
It has to do with the following line of code: - Producent(args[0],args[1],args[2],args[3]);
If you have no if statement it's even worse, what if args.length == 0? What if no args are inputted? Listen, do one of the following things:
Change your if condition to be (args.length > 3) or
Make an else if (args.length == 1), one for (args.length == 2) and one for args.length == 3 where you do different things in each.
Now are you understanding where the problem lies?
I hope this helped, good luck,
-blazed
but why it still throws the exception when i got rid of args.length ?
the exception is in thread main so i shouldn't look somewhere else for it ?
Your exception isn't thrown in your main method; it is thrown somewhere in the
same thread as the one in which the main method executed. Read the message
carefully: it mentions the method and line number where the exception was
thrown. It most certainly was not in your main method; it happened somewhere
where an array did have at most two elements because index 2 (see message)
was out of the array bounds.
or
alternatively that exception was thrown in the main method itself and you didn't
supply four arguments to your main method (less than three actually because
2 is an out of bound array index.
kind regards,
Jos
yes it's Producent producent=new Producent(args[0],args[1],args[2],args[3]); causing the exception on line 607
weird
it works fine with 2 parameters
but i need four for the queues
i bat i have 4 parameters
i checked it to be sure
yes it's Producent producent=new Producent(args[0],args[1],args[2],args[3]); causing the exception on line 607 it worked fine with 2 parameters
Well, there you have your solution: you should pass four argument to your main()
method if your constructor expects four arguments; simple as that.
kind regards,
Jos
Well, there you have your solution: you should pass four argument to your main()
method if your constructor expects four arguments; simple as that.
kind regards,
Jos
He should still have error/exception handling if someone/him inputs less then 4 or maybe more arguments though right? ;)
-blazed
it must be something wrong in bat file cos when i run it
>java Producent q1 q2 q3 q4 it works and app opens
He should still have error/exception handling if someone/him inputs less then 4 or maybe more arguments though right? ;)
-blazed
Yep; if the constructor for that class demands four arguments the user better
supply them all four, no more and no less and the code should elegantly bail
out if any other number of arguments is supplied. That entire little problem is
so old; an args.length != 4 test is all that's needed in this example.
kind regards,
Jos
it must be something wrong in bat file cos when i run it
>java Producent q1 q2 q3 q4 it works and app opens
You just run the bat file without supplying the arguments?
no in bat i 'm passing four arguments that's why i dont know why it happens
no in bat i 'm passing four arguments that's why i dont know why it happens
Use the "poor man's debugger": do this at the start of your main method: -
System.out.println("nof args: "+args.length);
-
for (int i= 0; i < args.length; i++)
-
System.out.println(i+": "+args[i];
-
and see what arguments are really passed to your main method. Always give
the bug less and less space to hide; finally you can pinpoint it and remove it.
Just guessing never helped anyone.
kind regards,
Jos
Use the "poor man's debugger": do this at the start of your main method: -
System.out.println("nof args: "+args.length);
-
for (int i= 0; i < args.length; i++)
-
System.out.println(i+": "+args[i];
-
and see what arguments are really passed to your main method. Always give
the bug less and less space to hide; finally you can pinpoint it and remove it.
Just guessing never helped anyone.
kind regards,
Jos
What's the "rich man's debugger" ?!
This is how I usually debug things...
-blazed
What's the "rich man's debugger" ?!
This is how I usually debug things...
-blazed
The "rich man's debugger" has a gui and a tremendous amount of buttons to
click and you don't know which one because there are also a myriad of options
to select and you finally end up clicking that little 'X' at the top right corner and
insert a couple of System.out.println() method calls and try again ;-)
kind regards,
Jos
The "rich man's debugger" has a gui and a tremendous amount of buttons to
click and you don't know which one because there are also a myriad of options
to select and you finally end up clicking that little 'X' at the top right corner and
insert a couple of System.out.println() method calls and try again ;-)
kind regards,
Jos
LOL. No wonder they say you're crazy.
LOL. No wonder they say you're crazy.
Duh; I have a pink inflatable axe that goes *beep!*
kind regards,
Jos ;-)
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Ravi Tallury |
last post by:
Hi
We are having issues with our application, certain portions of it stop
responding while the rest of the application is fine. I am attaching
the Java Core dump. If someone can let me know what...
|
by: CM |
last post by:
Hi,
when i want connect me in my BD with a JSP (with this simple code),
this exception is throw.
Thank's for ur help
Mathieu
CODE of my JSP
---------------------
|
by: Christoph Zwerschke |
last post by:
You will often hear that for reasons of fault minimization, you should
use a programming language with strict typing:
http://turing.une.edu.au/~comp284/Lectures/Lecture_18/lecture/node1.html
I...
|
by: ganesh.m |
last post by:
Hi,
I am new to DB2. I am getting this error while loading the DB2Driver. I
don't have any idea about where i might have gone wrong. please help
me.
Below is the stack trace.
Stack Trace:...
|
by: crazystone82 |
last post by:
Hi all,
please send me a source code to transfer a file to a server
running on another pc in the LAN...using JAVA .By getting the source path and destination path through textfield implemented...
|
by: Light |
last post by:
Hi
I m getting this error while i m trying to run my program and i don't understand why that happens.
import java.util.*;
public class Exercise6 {
|
by: bkquinn359 |
last post by:
Hi All,
I am getting the follwoing error
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
at Chp8Assign1.main(Chp8Assign1.java:37)
Press any key to continue...
...
|
by: ksheerasagar17 |
last post by:
Hello All,
Scenario: Sending an image through webservice as byte array to an Java webservice.
The Problem1: The webservice method image property expects (data type) SByte rather than Byte...
|
by: yeshello54 |
last post by:
so here is my problem...in a contact manager i am trying to complete i have ran into an error..we have lots of code because we have some from class which we can use...anyways i keep getting an error...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |