Results 1 to 11 of 11
  1. #1
    ara
    ara is offline Member
    Join Date
    Jan 2009
    Posts
    8
    Rep Power
    0

    Default [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.

  2. #2
    angryboy's Avatar
    angryboy is offline Senior Member
    Join Date
    Jan 2009
    Posts
    742
    Rep Power
    6

    Default

    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)

  3. #3
    angryboy's Avatar
    angryboy is offline Senior Member
    Join Date
    Jan 2009
    Posts
    742
    Rep Power
    6

    Default

    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)

  4. #4
    ara
    ara is offline Member
    Join Date
    Jan 2009
    Posts
    8
    Rep Power
    0

    Default

    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)

  5. #5
    angryboy's Avatar
    angryboy is offline Senior Member
    Join Date
    Jan 2009
    Posts
    742
    Rep Power
    6

    Default

    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)

  6. #6
    ara
    ara is offline Member
    Join Date
    Jan 2009
    Posts
    8
    Rep Power
    0

    Default

    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"

  7. #7
    angryboy's Avatar
    angryboy is offline Senior Member
    Join Date
    Jan 2009
    Posts
    742
    Rep Power
    6

    Default

    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)

  8. #8
    angryboy's Avatar
    angryboy is offline Senior Member
    Join Date
    Jan 2009
    Posts
    742
    Rep Power
    6

    Default

    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)

  9. #9
    ara
    ara is offline Member
    Join Date
    Jan 2009
    Posts
    8
    Rep Power
    0

    Default

    Java Code:
    public class adminPanel {
    
    	public JFrame jFrame = null;  //  @jve:decl-index=0:visual-constraint="91,33"
    	private JPanel jContentPane = null;
    the adminPanel jFrame is in public.. from the above code... (hope i'm saying relevant thing :S...) Right?..

    ****
    And no... i dont want it to be shown in the same window...)

  10. #10
    angryboy's Avatar
    angryboy is offline Senior Member
    Join Date
    Jan 2009
    Posts
    742
    Rep Power
    6

    Default

    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)

  11. #11
    ara
    ara is offline Member
    Join Date
    Jan 2009
    Posts
    8
    Rep Power
    0

    Default

    Oh!!.... Yesh!... solved!... Thanks soo much!!... =)
    *angryboy made me a really happy girl* Haha!
    Thanks soo much for your time!...
    Learnt smt new today! =)

Similar Threads

  1. Replies: 2
    Last Post: 12-14-2009, 01:46 AM
  2. Replies: 12
    Last Post: 10-05-2008, 06:52 AM
  3. Replies: 3
    Last Post: 01-29-2008, 01:37 AM
  4. Replies: 1
    Last Post: 08-06-2007, 06:04 PM
  5. Replies: 1
    Last Post: 07-16-2007, 06:32 AM

Posting Permissions

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