Results 1 to 4 of 4
  1. #1
    casta is offline Member
    Join Date
    Apr 2016
    Posts
    27
    Rep Power
    0

    Default Null pointer exception

    I receive a null-pointer exception with a small piece of extra code (new method) that looks almost identical to the existing code, that does work!
    I was not able to find what is going wrong. Perhaps you can help me with that:

    Java Code:
    	public ReadyEvent createReadyEvent(int time, Order O) {
    		ReadyEvent RE = new ReadyEvent(time, O);
    		return RE;
    	}
    	
    	public assignEvent createAssignEvent(int time) {
    		assignEvent AE = new assignEvent(time);
    		return AE;
    	}
    The above one is old, the one below is new.
    In the same class, I invoke both methods in my runEvent-method.

    Java Code:
    	public void runEvent(List<Event> listOfEvents) {
    		setOrderStatus(listOfEvents.get(0).orderOfEvent);
    
    		listOfEvents.add(createReadyEvent(eventTime, orderOfEvent));
    		listOfEvents.add(createAssignEvent(eventTime));
    The full code for class assignEvent =
    Java Code:
    import java.util.List;
    
    public class assignEvent extends Event{
    		
    		public assignEvent(int previousEventTime) {
    
    			this.eventType = "assignment";
    			this.eventTime = previousEventTime+2; //delaying assignment with 2 minutes
    			this.priority = 11;
    
    		}
    		
    		@Override
    		public String toString() { 
    			return String.format("%n").intern() + "" + eventTime + ", Event: " + eventType + ", prio: " + priority   ;
    			}
    
    		public void runEvent(List<Event> listOfEvents) {
    			TestDrive.assignOrder();
    			listOfEvents.remove(0);	
    		}
    }

    What do I do wrong here?
    Last edited by casta; 06-16-2016 at 09:34 AM.

  2. #2
    trcooke is offline Tim Cooke
    Join Date
    Jul 2014
    Location
    Belfast
    Posts
    101
    Rep Power
    0

    Default Re: Null pointer exception

    What line of that code is the NullPointerException thrown? This one perhaps?
    Java Code:
    setOrderStatus(listOfEvents.get(0).orderOfEvent);
    Is listOfEvents empty?

  3. #3
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    27

    Default Re: Null pointer exception

    When you get an exception it helps to post the full exception text, including the stack trace, and highlight the line in your code that it is thrown from, otherwise we are forced to guess, which tends to result in incorrect solutions.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  4. #4
    casta is offline Member
    Join Date
    Apr 2016
    Posts
    27
    Rep Power
    0

    Default Re: Null pointer exception

    Thank you for your replies and suggestion.

    I finally found the problem. I removed the Order argument on purpose when creating the assignEvent. Somewhere in the code of the method AssignOrder(), there was a equality check which required information from that Order Class. '

Similar Threads

  1. Null pointer exception
    By gevin20 in forum New To Java
    Replies: 2
    Last Post: 03-26-2014, 12:21 PM
  2. null pointer exception help
    By captain_turkiye in forum New To Java
    Replies: 17
    Last Post: 12-04-2011, 12:27 AM
  3. null pointer exception
    By Herah in forum New To Java
    Replies: 1
    Last Post: 12-01-2011, 08:44 AM
  4. Null pointer exception
    By DBaskov in forum New To Java
    Replies: 14
    Last Post: 07-10-2011, 11:16 PM
  5. Null Pointer exception (Again !!)
    By mobosecomin in forum New To Java
    Replies: 6
    Last Post: 03-29-2011, 05:04 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •