i get
Exception in thread "main" java.lang.Array IndexOutOfBound sException: 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 41043
i get
Exception in thread "main" java.lang.Array IndexOutOfBound sException: 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. IndexArrayOutOf Bounds 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
JosAH 11,448
Recognized Expert MVP
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
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 the issue is.
Thanks
Ravi
|
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 just came across a funny example in which the opposite is the case.
The following is a binary search algorithm in Java. It searches a value
in an ordered array a of ints:
public static int binarySearch(int a, int key) {
|
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:
java.lang.ExceptionInInitializerError:
|
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 in java swings
| |
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...
In this program...
public class Chp8Assign1 {
|
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 array. Thus i'm converting a byte array to sbyte array and sending through web service. The converted SByte contains negative numbers wihch are resulting in an error "java.lang.ArrayIndexOutOfBoundsException: -106"
Byte => SByte...error...
|
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 when i do the following. if you add a contact with up to 13 fields it will be stored in a data structure. i have a tabbed pane that will show six of the 13 fields for that contact. when you double click the contact i want it to pop up and show all 13...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |