|
|
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.
|
|

04-29-2008, 02:14 AM
|
|
Member
|
|
Join Date: Apr 2008
Posts: 2
|
|
|
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, 04:44 AM
|
 |
Senior Member
|
|
Join Date: Jan 2008
Location: Cebu City, Philippines
Posts: 524
|
|
|
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.
|
|

04-29-2008, 05:28 AM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 2,968
|
|
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 September 4, 2008)
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
|

04-29-2008, 05:37 AM
|
 |
Senior Member
|
|
Join Date: Apr 2008
Posts: 386
|
|
|
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, 07:57 PM
|
|
Member
|
|
Join Date: Apr 2008
Posts: 2
|
|
|
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, 08:15 PM
|
 |
Senior Member
|
|
Join Date: Apr 2008
Posts: 386
|
|
|
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, 04:48 AM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 2,968
|
|
yes aldo, your question is not clear. And some coding styles are pointless, as Zosden says,
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 September 4, 2008)
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|