473,799 Members | 2,940 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

java.lang.Array IndexOutOfBound sException

oll3i
679 Contributor
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

Expand|Select|Wrap|Line Numbers
  1. public static void main(String[] args){
  2.  
  3.  
  4.  
  5.         if (args.length < 1 || args.length > 4) {
  6.             System.out.println("usage: <destination> <destination> <destination> <destination>");
  7.             System.exit(1);
  8.         }else {Producent producent=new Producent(args[0],args[1],args[2],args[3]);}
  9.          /// producent.close();
  10.  
  11.       }     
  12. }
  13.  
thank you
Jun 11 '07
22 41046
oll3i
679 Contributor
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
Jun 11 '07 #11
oll3i
679 Contributor
i bat i have 4 parameters
i checked it to be sure
Jun 11 '07 #12
JosAH
11,448 Recognized Expert MVP
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
Jun 11 '07 #13
blazedaces
284 Contributor
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
Jun 11 '07 #14
oll3i
679 Contributor
it must be something wrong in bat file cos when i run it
>java Producent q1 q2 q3 q4 it works and app opens
Jun 11 '07 #15
JosAH
11,448 Recognized Expert MVP
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
Jun 11 '07 #16
r035198x
13,262 MVP
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?
Jun 11 '07 #17
oll3i
679 Contributor
no in bat i 'm passing four arguments that's why i dont know why it happens
Jun 11 '07 #18
JosAH
11,448 Recognized Expert MVP
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:

Expand|Select|Wrap|Line Numbers
  1. System.out.println("nof args: "+args.length);
  2. for (int i= 0; i < args.length; i++)
  3.    System.out.println(i+": "+args[i];
  4.  
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
Jun 11 '07 #19
blazedaces
284 Contributor
Use the "poor man's debugger": do this at the start of your main method:

Expand|Select|Wrap|Line Numbers
  1. System.out.println("nof args: "+args.length);
  2. for (int i= 0; i < args.length; i++)
  3.    System.out.println(i+": "+args[i];
  4.  
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
Jun 11 '07 #20

Sign in to post your reply or Sign up for a free account.

Similar topics

0
6816
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
1
10713
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 ---------------------
26
3252
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) {
6
6495
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:
24
7409
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
6
24262
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 {
2
2013
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 {
2
9789
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...
2
3767
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...
0
9687
marktang
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...
0
9541
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,...
0
10482
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
6805
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5463
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5585
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4139
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
2
3759
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2938
bsmnconsultancy
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.