Results 1 to 7 of 7
Thread: IndexOutOfBoundsException
- 04-29-2008, 01:14 AM #1
Member
- Join Date
- Apr 2008
- Posts
- 11
- Rep Power
- 0
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!
- 04-29-2008, 03:44 AM #2
Can you show as your get(int index) method?
freedom exists in the world of ideas
- 04-29-2008, 04:28 AM #3
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
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.
- 04-29-2008, 04:37 AM #4
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
- 04-29-2008, 06:57 PM #5
Member
- Join Date
- Apr 2008
- Posts
- 11
- Rep Power
- 0
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.
- 04-29-2008, 07:15 PM #6
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
- 04-30-2008, 03:48 AM #7
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
yes aldo, your question is not clear. And some coding styles are pointless, as Zosden says,
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.Java Code:if(destinations.isEmpty() == true && pickups.isEmpty() == true)


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks