Results 1 to 6 of 6
  1. #1
    Pulgo is offline Member
    Join Date
    Jan 2011
    Posts
    3
    Rep Power
    0

    Default Nullpointerexception?

    Hi, I got a nullpointerexception. I've looked everywhere in my code, but since I'm quite new to java I can't find what's causing my problem.

    Here's the error-msg:

    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    at isp.Controller.addProduktToOrder(Controller.java:2 59)
    at isp.KundRegUI.addProduktToOrderButtonActionPerform ed(KundRegUI.java:894)
    at isp.KundRegUI.access$1900(KundRegUI.java:11)
    at isp.KundRegUI$20.actionPerformed(KundRegUI.java:28 2)
    at java.awt.Button.processActionEvent(Button.java:388 )
    at java.awt.Button.processEvent(Button.java:356)
    at java.awt.Component.dispatchEventImpl(Component.jav a:4068)
    at java.awt.Component.dispatchEvent(Component.java:39 03)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java: 463)
    at java.awt.EventDispatchThread.pumpOneEventForHierar chy(EventDispatchThread.java:269)
    at java.awt.EventDispatchThread.pumpEventsForHierarch y(EventDispatchThread.java:190)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:184)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:176)
    at java.awt.EventDispatchThread.run(EventDispatchThre ad.java:110)
    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    at isp.Controller.addProduktToOrder(Controller.java:2 59)
    at isp.KundRegUI.addProduktToOrderButtonActionPerform ed(KundRegUI.java:894)
    at isp.KundRegUI.access$1900(KundRegUI.java:11)
    at isp.KundRegUI$20.actionPerformed(KundRegUI.java:28 2)
    at java.awt.Button.processActionEvent(Button.java:388 )
    at java.awt.Button.processEvent(Button.java:356)
    at java.awt.Component.dispatchEventImpl(Component.jav a:4068)
    at java.awt.Component.dispatchEvent(Component.java:39 03)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java: 463)
    at java.awt.EventDispatchThread.pumpOneEventForHierar chy(EventDispatchThread.java:269)
    at java.awt.EventDispatchThread.pumpEventsForHierarch y(EventDispatchThread.java:190)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:184)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:176)
    at java.awt.EventDispatchThread.run(EventDispatchThre ad.java:110)
    And here's the method that the error points at. I don't know if the problem lies in this method or some other method in the class controller?

    Java Code:
    public void addProduktToOrder(String kundNummer, String orderNr, String produktNr, int antal, int radNr){
            Kund tmpKund;
            Kund aKund = null;
            tmpKund = kundReg.findKund(kundNummer);
    
                if(tmpKund != null){
                    aKund = tmpKund;
                }
    
            
            Order tmpOrder;
    
            tmpOrder = aKund.findOrder(orderNr); /// HÄR ÄR FAILEN NU
            
            Produkt tmpProdukt = prodReg.findProdukt(produktNr);
            
            OrderRad tmpOrderRad = new OrderRad();
    
                
                tmpOrderRad.setProdukt(tmpProdukt);
                tmpOrderRad.setAntal(antal);
                tmpOrderRad.setRadNr(radNr);
                tmpOrderRad.setOrder(tmpOrder);
    
                tmpProdukt.addOrderRad(tmpOrderRad);
                [B]tmpOrder.addOrderRad(tmpOrderRad); [/B]
    
        }
    More specifically the error points att the bold line.

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,802
    Rep Power
    19

    Default

    tmpOrder is null, which means that aKund.findOrder(orderNr) returns null for whatever value it is you are supplying it.

  3. #3
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    787
    Rep Power
    5

    Default

    tmpOrder = aKund.findOrder(orderNr);

    What happens if the method doesn`t find the order? It will return null or? So you call the addOrderRad on a null-reference --> NPE !

  4. #4
    Pulgo is offline Member
    Join Date
    Jan 2011
    Posts
    3
    Rep Power
    0

    Default

    Okay. But why is tmpOrder null?

    Is it because aKund is declared as null above? Because tmpOrder itself is never declared as null?

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,802
    Rep Power
    19

    Default

    I explained why.
    findOrder is returning null.
    So whatever that method does is returning null, presumably because it can't find the order.

  6. #6
    Pulgo is offline Member
    Join Date
    Jan 2011
    Posts
    3
    Rep Power
    0

    Default

    Quote Originally Posted by Tolls View Post
    I explained why.
    findOrder is returning null.
    So whatever that method does is returning null, presumably because it can't find the order.
    Okey. I solved it. Thanks for the help!

Similar Threads

  1. NullPointerException help me!
    By phancuong87 in forum New To Java
    Replies: 4
    Last Post: 01-19-2010, 04:01 PM
  2. NullPointerException
    By tommyyyy in forum New To Java
    Replies: 9
    Last Post: 03-26-2009, 10:51 PM
  3. NullPointerException I NEED HELP
    By mayhewj7 in forum New To Java
    Replies: 2
    Last Post: 02-13-2009, 08:03 AM
  4. NullPointerException
    By adeeb in forum AWT / Swing
    Replies: 3
    Last Post: 06-11-2008, 08:42 AM
  5. NullPointerException
    By mensa in forum Java 2D
    Replies: 5
    Last Post: 05-03-2008, 11:19 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
  •