Results 1 to 8 of 8
- 11-24-2011, 02:30 PM #1
Member
- Join Date
- Nov 2011
- Posts
- 4
- Rep Power
- 0
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)
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; } } }
thank you
ZezinzLast edited by Fubarable; 11-24-2011 at 02:56 PM. Reason: code tags added
- 11-24-2011, 02:53 PM #2
Re: 3 tier architecture causing problems
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at Logic.doesUserExist(Logic.java:43)
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.
-
Re: 3 tier architecture causing problems
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; } } }
- 11-24-2011, 03:34 PM #4
Member
- Join Date
- Nov 2011
- Posts
- 4
- Rep Power
- 0
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
-
Re: 3 tier architecture causing problems
- 11-24-2011, 05:08 PM #6
Member
- Join Date
- Nov 2011
- Posts
- 4
- Rep Power
- 0
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."); } }
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 05:13 PM. Reason: Made it into code
-
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.
- 11-24-2011, 05:32 PM #8
Member
- Join Date
- Nov 2011
- Posts
- 4
- Rep Power
- 0
Similar Threads
-
Servlet on 3 and 2 tier architecture NEED HELP
By lol-y-noob in forum Java ServletReplies: 1Last Post: 08-27-2011, 11:45 PM -
Need explanation on 2 tier and 3 tier. Thank you
By SnoopyX in forum EclipseReplies: 2Last Post: 03-25-2011, 06:56 AM -
Recursive for loop causing problems
By Catfish1 in forum New To JavaReplies: 2Last Post: 02-22-2011, 04:12 PM -
Confusion about DAO in Three-Tier Architecture!
By Maven0 in forum New To JavaReplies: 4Last Post: 07-26-2010, 02:30 PM -
Persistence causing problems with JButton 2D Array
By easyp in forum New To JavaReplies: 2Last Post: 04-21-2010, 07:34 PM
Bookmarks