Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-29-2008, 02:14 AM
Member
 
Join Date: Apr 2008
Posts: 2
aldo1987 is an unknown quantity at this point
IndexOutOfBoundsException
Well i have e f**k off project in for thursday and i have a little runtime error that goes as such :-

notifyPassengerArrival(passengers.get(0));

on this line i want to return the first element in the array (a Passenger object) and pass it to the notifyPassengerArrival method, but i keep getting an IndexOutOfBoundsException.

I have confirmed that the array is not empty by using a println, so there is definetly an object at 0 in the array.

I just dont get it!
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 04-29-2008, 04:44 AM
sukatoa's Avatar
Senior Member
 
Join Date: Jan 2008
Location: Cebu City, Philippines
Posts: 509
sukatoa is on a distinguished road
Send a message via Yahoo to sukatoa
Can you show as your get(int index) method?
__________________
A specific, detailed, simple, well elaborated, and "tested before asking" question may gather more quick replies. hopefully
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 04-29-2008, 05:28 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 2,403
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Hi aldo1987,

Welcome to our community.

Yes, put some code here we can check/test. You say that, it is confirmed using println(), so what is the output? May be after that array content can be changed.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
(Close on July 13, 2008)
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 04-29-2008, 05:37 AM
Zosden's Avatar
Senior Member
 
Join Date: Apr 2008
Posts: 354
Zosden is on a distinguished road
Please don't you curse words, they just make you sound incompetent. If you post some code then we can help you.
__________________
My IP address is 127.0.0.1
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 04-29-2008, 07:57 PM
Member
 
Join Date: Apr 2008
Posts: 2
aldo1987 is an unknown quantity at this point
public void act()
{
//ADDED ENTIRE ACT FUNCTIONALITY
if(destinations.isEmpty() == true && pickups.isEmpty() == true)
{
incrementIdleCount();
}

else
{
chooseTargetLocation();
Location target = getTargetLocation();
if(target != null) {
// Find where to move to next.
Location next = getLocation().nextLocation(target);
setLocation(next);
if(next.equals(target))
{
if(target == pickups.get(0))
{
notifyPickupArrival();
}
else if(target == destinations.get(0))
{
System.out.println(passengers.get(0));
notifyPassengerArrival(passengers.get(0));
offloadPassenger();
}


}
}

}


}

this is the method my problem appears in, The result of my println is "Passenger travelling from location 2,28 to location 18,21", in accordance with the toString method of the passenger class.
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 04-29-2008, 08:15 PM
Zosden's Avatar
Senior Member
 
Join Date: Apr 2008
Posts: 354
Zosden is on a distinguished road
Congratulation's for maintaining the ability to write Unmaintainable code. isEmpty = true is extremely redundant. Thats like saying is 1 = 1. I mean come on. Second thing I have absolutely know idea what this code does. Your passing in magic numbers into other methods that I can't see. Also please put your code in the code blocks next time it makes it more readable.
__________________
My IP address is 127.0.0.1
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 04-30-2008, 04:48 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 2,403
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
yes aldo, your question is not clear. And some coding styles are pointless, as Zosden says,

Code:
if(destinations.isEmpty() == true && pickups.isEmpty() == true)
no real mean of this. It's legal to use, but not good to use. isEmpty() always return a boolean value. So why did you comparing it again.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
(Close on July 13, 2008)
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +3. The time now is 11:35 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org