From: David W. <d.a...@st...> - 2011-08-28 23:53:52
|
Dear All, I have a problem which i cannot put my finger on. In my model i have a class Tour, a class Vehicle and a class Carrier. When i want to add the Tour object from within the carrier object to an ArrayList<Tour> within the object Vehicle i get a nullpointer exception error. Passing a primitive does not give the same error. The code in the carrier class: Iterator<Tour> itrTour = this.ToursCR.iterator(); while(itrTour.hasNext())//As long as there are tours within the TourList { tour = itrTour.next(); System.out.println("@Route_To_Truck @Carrier: tour length: " + tour.getTourLength()); if((index2 < size2))// && (assignRemaining == false)) { VehicleCR v = this.Fleet.get(index2); System.out.println("@Route_To_Truck @Carrier: vehicle is: " + v.getId()); here the object "tour" is passed ----->v.setTourList(tour); Fleet.set(index2, v); } The method "setTourList" within the vehicle is: public void setTourList(Tour tour) { this.TourList.add(tour); //Adds an a tour at the end of an arrayList } I have tried setting the ArrayList "TourList" to private or public but i keep getting the same error which i also get when i want to pass an ArrayList to a method. All help will be appreciated. Kind regards, David Watson -- View this message in context: http://old.nabble.com/Null-pointer-exception-error-when-passing-object-to-method-tp32353745p32353745.html Sent from the repast-interest mailing list archive at Nabble.com. |