Results 1 to 8 of 8
  1. #1
    zezinz is offline Member
    Join Date
    Nov 2011
    Posts
    4
    Rep Power
    0

    Default 3 tier architecture causing problems

    Hello

    We are having some problems with our code after converting our code from just one form to the 3 tier architecture
    The problem seems to be between our gui and logic layer.

    When we run our program we get a nullpointer exception, i will just link the code and exception.

    Java Code:
    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    	at Logic.doesUserExist(Logic.java:43)
    	at GUI.jButton4ActionPerformed(GUI.java:643)
    	at GUI.access$000(GUI.java:2)
    	at GUI$1.actionPerformed(GUI.java:124)
    	at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
    	at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
    	at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
    	at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
    	at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
    	at java.awt.Component.processMouseEvent(Component.java:6267)
    	at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
    	at java.awt.Component.processEvent(Component.java:6032)
    	at java.awt.Container.processEvent(Container.java:2041)
    	at java.awt.Component.dispatchEventImpl(Component.java:4630)
    	at java.awt.Container.dispatchEventImpl(Container.java:2099)
    	at java.awt.Component.dispatchEvent(Component.java:4460)
    	at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4577)
    	at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4238)
    	at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
    	at java.awt.Container.dispatchEventImpl(Container.java:2085)
    	at java.awt.Window.dispatchEventImpl(Window.java:2478)
    	at java.awt.Component.dispatchEvent(Component.java:4460)
    	at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
    	at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
    	at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
    	at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
    	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
    	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
    	at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
    This is our code for our gui where i have cut out the constructor, some used get methods and the button we press

    Java Code:
    public class GUI extends javax.swing.JFrame {
    public Logic l;
        
        public GUI() { 
            initComponents();
            jDialog1.setVisible(true);
            l = new Logic(); 
            
        }
     public String getUser(){
                 return jTextField5.getText();
             }
    public char[] getPass(){
                 return jPasswordField1.getPassword();
             }
    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        if(l.doesUserExist() == true ){
        
            if(l.doesPatientExist() == true ){
                        setVisible(false);
                        jLabel8.setText("Patient do not exist.");
                        jDialog3.setVisible(true); 
            }
            
            else{
                jTextField7.setText(l.getdName() + ", " + l.getdCPR() + ".");
                jTextField11.setText(l.getdName());
                jTextField2.setText(l.getdCPR());
                jTextField9.setText(l.getdAdd());
                jTextField3.setText(Integer.toString(l.getdTelnr()));
                jTextField6.setText(l.getdComment());   
            }
        }
        else{
        jDialog3.setVisible(true);
        jLabel8.setText("Wrong password/username.");
        }
    
    }
    }

    This is our logic class where i have cut out the constructor and the method we call in the gui layer.

    Java Code:
    public class Logic {
        
        private GUI g;
        
        private Data d;
        
        public Logic(){
           d = new Data();
        }
    public boolean doesUserExist(){
           
           if(g.getUser().equals("Lęge"))
            {  
            String a = String.valueOf(g.getPass());
                if(a.equals("1234"))
                {
                return true;            
                }
                else
                {
                return false;
                }
            }
            else
            {
            return false;
            }
           }
       }
    From what i can see is the fault is at line 43 at the if sentence in the logic, but i cant figure out what the exception is.

    thank you
    Zezinz
    Last edited by Fubarable; 11-24-2011 at 01:56 PM. Reason: code tags added

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default Re: 3 tier architecture causing problems

    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    at Logic.doesUserExist(Logic.java:43)
    There is a null variable on line 43 in Logic.java. Look at that line of code and find the null variable. Then backtrack to see why that variable does not have a valid value.
    If you can not see what variable is null, add a println just before line 43 to print out the values of all the variables used on line 43.

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: 3 tier architecture causing problems

    Quote Originally Posted by zezinz View Post
    Hello
    Hello and welcome to Java-Forums.org!

    I have taken the liberty of adding code tags to your post. If you edit it, you'll see how I did it.


    This is our logic class where i have cut out the constructor and the method we call in the gui layer.

    Java Code:
    public class Logic {
        
        private GUI g;
        
        private Data d;
        
        public Logic(){
           d = new Data();
        }
    public boolean doesUserExist(){
           
           if(g.getUser().equals("Lęge"))
            {  
            String a = String.valueOf(g.getPass());
                if(a.equals("1234"))
                {
                return true;            
                }
                else
                {
                return false;
                }
            }
            else
            {
            return false;
            }
           }
       }
    From what i can see is the fault is at line 43 at the if sentence in the logic, but i cant figure out what the exception is.
    What I can't see is where you've set your GUI variable, g, to refer to a valid GUI object. Usually this would require giving the Logic class a mutator or setter method, perhaps one called setGui(GUI g) and calling it from the controller or from whatever class starts the whole program and creates and displays GUI.

  4. #4
    zezinz is offline Member
    Join Date
    Nov 2011
    Posts
    4
    Rep Power
    0

    Default Re: 3 tier architecture causing problems

    thank you for your help.
    we found out that we needed to send a parameter with the method to the logic class.
    so it is now fixed

    Zezinz

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: 3 tier architecture causing problems

    Quote Originally Posted by zezinz View Post
    thank you for your help.
    we found out that we needed to send a parameter with the method to the logic class.
    so it is now fixed
    I'm glad that it's fixed, but I'm confused by what you mean by "a parameter with 'the method'"? Are you sure that the parameter isn't a GUI object either in a setter method as I mentioned above or in the constructor?

  6. #6
    zezinz is offline Member
    Join Date
    Nov 2011
    Posts
    4
    Rep Power
    0

    Default Re: 3 tier architecture causing problems

    we changed our code to

    Java Code:
    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        if(l.doesUserExist(getUser(), getPass()) == true ){ //added getUser() and getPass()
        
            if(l.doesPatientExist(getCPR()) == true ){ //add getCPR()
                        setVisible(false);
                        jLabel8.setText("Patient do not exist.");
                        jDialog3.setVisible(true); 
            }
            
            else{
                jTextField7.setText(l.getdName() + ", " + l.getdCPR() + ".");
                jTextField11.setText(l.getdName());
                jTextField2.setText(l.getdCPR());
                jTextField9.setText(l.getdAdd());
                jTextField3.setText(Integer.toString(l.getdTelnr()));
                jTextField6.setText(l.getdComment());
                setVisible(true);
                jDialog1.dispose();
                l.getBlobFromDatabase(l.getdCPR(), l.getdName());
            }
        }
        else{
        jDialog3.setVisible(true);
        jLabel8.setText("Wrong password/username.");
        }
    
    }
    By parameters we mean the bold methods so we can transfer some variables to the other class.


    Java Code:
    public boolean doesUserExist(String user, char[] pass){ //added String user and char[] pass
           
           if(user.equals("Lęge")) //added user
            {  
            String a = String.valueOf(pass); // added pass
                if(a.equals("1234"))
                {
                return true;            
                }
                else
                {
                return false;
                }
            }
            else
            {
            return false;
            }
           }

    then we use those parameters here in the other class, instead of calling the methods across the class.
    Last edited by zezinz; 11-24-2011 at 04:13 PM. Reason: Made it into code

  7. #7
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: 3 tier architecture causing problems

    OK, got it.

    As an aside, please don't try to "bold" or italicize posted code. Instead use code tags so your code is readable. Please edit your code above to see how I have added code tags to your post.

  8. #8
    zezinz is offline Member
    Join Date
    Nov 2011
    Posts
    4
    Rep Power
    0

    Default Re: 3 tier architecture causing problems

    yes i made it bold at first because i couldnt figure out how to use code tags :) but i found out.

Similar Threads

  1. Servlet on 3 and 2 tier architecture NEED HELP
    By lol-y-noob in forum Java Servlet
    Replies: 1
    Last Post: 08-27-2011, 10:45 PM
  2. Replies: 2
    Last Post: 03-25-2011, 05:56 AM
  3. Recursive for loop causing problems
    By Catfish1 in forum New To Java
    Replies: 2
    Last Post: 02-22-2011, 03:12 PM
  4. Confusion about DAO in Three-Tier Architecture!
    By Maven0 in forum New To Java
    Replies: 4
    Last Post: 07-26-2010, 01:30 PM
  5. Replies: 2
    Last Post: 04-21-2010, 06:34 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
  •