Results 1 to 11 of 11
Thread: [SOLVED] pls help :S . "Exception in thread "AWT-EventQueue-0" java.lang.NullPointerE
- 01-29-2009, 06:43 AM #1
Member
- Join Date
- Jan 2009
- Posts
- 8
- Rep Power
- 0
[SOLVED] pls help :S . "Exception in thread "AWT-EventQueue-0" java.lang.NullPointerE
Pls help me... I cant seem to see what is wrong here... Here's how its supposed to work: When i click on the 'submit' button in LoginForm.java, its supposed to go to the adminPanel.java. Below are the codes..
******************************
LoginForm.java
******************************
***************************************Java Code:public class LoginForm { private JFrame jFrame = null; private JPanel jContentPane = null; private JLabel jLabel = null; private JLabel jLabelLoginId = null; private JLabel jLabel1 = null; private JTextField jTextFieldLoginId = null; private JButton jButtonSubmit = null; private JPasswordField jPasswordField = null; private JFrame getJFrame() { if (jFrame == null) { jFrame = new JFrame(); jFrame.setBounds(new java.awt.Rectangle(150,100,400,250)); jFrame.setTitle("Login Form"); jFrame.setContentPane(getJContentPane()); } return jFrame; } private JPanel getJContentPane() { if (jContentPane == null) { jLabel1 = new JLabel(); jLabel1.setBounds(new java.awt.Rectangle(60,120,70,20)); jLabel1.setText("Password:"); jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); jLabelLoginId = new JLabel(); jLabelLoginId.setBounds(new java.awt.Rectangle(60,75,70,20)); jLabelLoginId.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); jLabelLoginId.setText("Login Id:"); jLabel = new JLabel(); jLabel.setBounds(new java.awt.Rectangle(90,15,205,31)); jLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); jLabel.setText("Course Management System"); jContentPane = new JPanel(); jContentPane.setLayout(null); jContentPane.add(jLabel, null); jContentPane.add(jLabelLoginId, null); jContentPane.add(jLabel1, null); jContentPane.add(getJTextFieldLoginId(), null); jContentPane.add(getJButtonSubmit(), null); jContentPane.add(getJPasswordField(), null); } return jContentPane; } /** * This method initializes jButtonSubmit * * @return javax.swing.JButton */ private JButton getJButtonSubmit() { if (jButtonSubmit == null) { jButtonSubmit = new JButton(); jButtonSubmit.setBounds(new java.awt.Rectangle(150,165,75,25)); jButtonSubmit.setText("Submit"); jButtonSubmit.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { submitLogin(); } }); } return jButtonSubmit; } public void submitLogin(){ String id = getJTextFieldLoginId().getText(); String pwd = new String(getJPasswordField().getPassword()); System.out.println(id + " " + pwd); if (id.equals("") || pwd.equals("")) JOptionPane.showMessageDialog(null, "Please enter both text field"); else{ User user = new User(id, pwd); if (user.isExist()){ //getJFrame().dispose(); adminPanel ap = new adminPanel(); ap.jFrame.setVisible(true); } else JOptionPane.showMessageDialog(null, "Invalid Login. Try again"); } } public static void main(String [] args){ LoginForm loginForm = new LoginForm(); loginForm.getJFrame().setVisible(true); } }
adminPanel.java
***************************************
***************Java Code:public class adminPanel { public JFrame jFrame = null; // @jve:decl-index=0:visual-constraint="91,33" private JPanel jContentPane = null; private JMenuBar jJMenuBar = null; private JMenu jMenu = null; private JMenuItem jMenuItem_tourPlan = null; private JMenuItem jMenuItem_user = null; private JMenuItem jMenuItem_infoAni = null; private JMenuItem jMenuItem_infoVeggi = null; private JMenuItem jMenuItem_cal = null; private JMenuItem jMenuItem_feedback = null; private JMenuItem jMenuItem_testimonial = null; /** * This method initializes jFrame * * @return javax.swing.JFrame */ private JFrame getJFrame() { if (jFrame == null) { jFrame = new JFrame(); jFrame.setSize(new java.awt.Dimension(531,333)); jFrame.setTitle("AdminPanel"); jFrame.setJMenuBar(getJJMenuBar()); jFrame.setContentPane(getJContentPane()); } return jFrame; } /** * This method initializes jContentPane * * @return javax.swing.JPanel */ private JPanel getJContentPane() { if (jContentPane == null) { jContentPane = new JPanel(); jContentPane.setLayout(null); } return jContentPane; } //..... public static void main(String [] args){ adminPanel ad = new adminPanel(); ad.getJFrame().setVisible(true); } }
Here's the error that is shown
***************
ara ara
connection is jdbc:odbc:RuralTourism
DB Query: SELECT * FROM User WHERE UserName ='ara' and Password ='ara'
Connection is closed
//below is the error :S
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at AdminUser.LoginForm.submitLogin(LoginForm.java:108 )
at AdminUser.LoginForm$1.actionPerformed(LoginForm.ja va:91)
at javax.swing.AbstractButton.fireActionPerformed(Unk nown Source)
at javax.swing.AbstractButton$Handler.actionPerformed (Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed (Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseRe leased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent( Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(U nknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unkno wn Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilter s(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(U nknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarch y(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
**********************
Really apprecitae your time in trying to help =)
1st time asking a qn in Forum. So forgive me if i'm doing smt wrong.. :P
Thanks.. =)Last edited by ara; 01-29-2009 at 07:03 AM.
- 01-29-2009, 06:47 AM #2
i will look over you code, in the mean time...
please edit your OP to use code tags like this
XML Code:[code] codes here ... [/code]
USE CODE TAGS--> [CODE]...[/CODE]
Get NotePad++ (free)
- 01-29-2009, 06:55 AM #3
getJContentPane(): you have alot of space typo.
is this the complete code? i'm getting symbol not found.
one of them is: getJJMenuBar()USE CODE TAGS--> [CODE]...[/CODE]
Get NotePad++ (free)
- 01-29-2009, 07:00 AM #4
Member
- Join Date
- Jan 2009
- Posts
- 8
- Rep Power
- 0
oh... nono... its not... :S .. I removed the properties for the JMenuBar and JMenu Items and all... 'cos i didnt think it was of any use... as in nothing would go wrong in there right?... i just posted the codes where there would be probable errors... (hope u know wat i'm trying to say... :S)
- 01-29-2009, 07:30 AM #5
take a look at submitLogin().
ap.jFrame.setVisible(true);
isn't it suppose to be:
ap.getJFrame().setVisible(true);USE CODE TAGS--> [CODE]...[/CODE]
Get NotePad++ (free)
- 01-29-2009, 07:39 AM #6
Member
- Join Date
- Jan 2009
- Posts
- 8
- Rep Power
- 0
actually i've tried this b4... But there was error when i tried that... Here's the error:
"The method getJFrame() from the type adminPanel is not visible"
- 01-29-2009, 07:40 AM #7
did u make it public? it worked for me when i changed it to public in adminPanel.
USE CODE TAGS--> [CODE]...[/CODE]
Get NotePad++ (free)
- 01-29-2009, 07:41 AM #8
if you want to open in the same frame, you'll have to rewrite your code in a different way.
USE CODE TAGS--> [CODE]...[/CODE]
Get NotePad++ (free)
- 01-29-2009, 07:50 AM #9
Member
- Join Date
- Jan 2009
- Posts
- 8
- Rep Power
- 0
the adminPanel jFrame is in public.. from the above code... (hope i'm saying relevant thing :S...) Right?..Java Code:public class adminPanel { public JFrame jFrame = null; // @jve:decl-index=0:visual-constraint="91,33" private JPanel jContentPane = null;
****
And no... i dont want it to be shown in the same window...)
- 01-29-2009, 07:53 AM #10
no not the class, the method getJFrame() is private.
it'll work when you make it public.
----
if the post is solved, mark it as solved by using the Thread Tools toolbar at the very top of this page.USE CODE TAGS--> [CODE]...[/CODE]
Get NotePad++ (free)
- 01-29-2009, 08:00 AM #11
Member
- Join Date
- Jan 2009
- Posts
- 8
- Rep Power
- 0
Similar Threads
-
Exception in thread "AWT-EventQueue-0" java.lang.IllegalStateException:
By satishkumar_lskin in forum AWT / SwingReplies: 2Last Post: 12-14-2009, 01:46 AM -
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
By iuna in forum AWT / SwingReplies: 12Last Post: 10-05-2008, 06:52 AM -
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
By hemanthjava in forum AWT / SwingReplies: 3Last Post: 01-29-2008, 01:37 AM -
Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException
By leonard in forum New To JavaReplies: 1Last Post: 08-06-2007, 06:04 PM -
ArrayList: Exception in thread "main" java.lang.NullPointerException
By susan in forum New To JavaReplies: 1Last Post: 07-16-2007, 06:32 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks