Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-29-2009, 07:43 AM
ara ara is offline
Member
 
Join Date: Jan 2009
Posts: 8
Rep Power: 0
ara is on a distinguished road
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
******************************
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
***************************************
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 jdbcdbc: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 08:03 AM.
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 01-29-2009, 07:47 AM
angryboy's Avatar
Senior Member
 
Join Date: Jan 2009
Location: Javaland
Posts: 742
Rep Power: 2
angryboy is on a distinguished road
Default
i will look over you code, in the mean time...
please edit your OP to use code tags like this
HTML Code:
[code]
codes here
...
[/code]
__________________
USE CODE TAGS--> [CODE]...[/CODE]
Get NotePad++ (free)
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 01-29-2009, 07:55 AM
angryboy's Avatar
Senior Member
 
Join Date: Jan 2009
Location: Javaland
Posts: 742
Rep Power: 2
angryboy is on a distinguished road
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)
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 01-29-2009, 08:00 AM
ara ara is offline
Member
 
Join Date: Jan 2009
Posts: 8
Rep Power: 0
ara is on a distinguished road
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)
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 01-29-2009, 08:30 AM
angryboy's Avatar
Senior Member
 
Join Date: Jan 2009
Location: Javaland
Posts: 742
Rep Power: 2
angryboy is on a distinguished road
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)
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 01-29-2009, 08:39 AM
ara ara is offline
Member
 
Join Date: Jan 2009
Posts: 8
Rep Power: 0
ara is on a distinguished road
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"
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 01-29-2009, 08:40 AM
angryboy's Avatar
Senior Member
 
Join Date: Jan 2009
Location: Javaland
Posts: 742
Rep Power: 2
angryboy is on a distinguished road
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)
Bookmark Post in Technorati
Reply With Quote
  #8 (permalink)  
Old 01-29-2009, 08:41 AM
angryboy's Avatar
Senior Member
 
Join Date: Jan 2009
Location: Javaland
Posts: 742
Rep Power: 2
angryboy is on a distinguished road
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)
Bookmark Post in Technorati
Reply With Quote
  #9 (permalink)  
Old 01-29-2009, 08:50 AM
ara ara is offline
Member
 
Join Date: Jan 2009
Posts: 8
Rep Power: 0
ara is on a distinguished road
Default
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...)
Bookmark Post in Technorati
Reply With Quote
  #10 (permalink)  
Old 01-29-2009, 08:53 AM
angryboy's Avatar
Senior Member
 
Join Date: Jan 2009
Location: Javaland
Posts: 742
Rep Power: 2
angryboy is on a distinguished road
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)
Bookmark Post in Technorati
Reply With Quote
  #11 (permalink)  
Old 01-29-2009, 09:00 AM
ara ara is offline
Member
 
Join Date: Jan 2009
Posts: 8
Rep Power: 0
ara is on a distinguished road
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! =)
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Exception in thread "AWT-EventQueue-0" java.lang.IllegalStateException: satishkumar_lskin AWT / Swing 2 12-14-2009 02:46 AM
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException iuna AWT / Swing 12 10-05-2008 07:52 AM
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException hemanthjava AWT / Swing 3 01-29-2008 02:37 AM
Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException leonard New To Java 1 08-06-2007 07:04 PM
ArrayList: Exception in thread "main" java.lang.NullPointerException susan New To Java 1 07-16-2007 07:32 AM


All times are GMT +2. The time now is 07:46 AM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org