Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Feb 7th, 2005, 12:17 PM   #1
GoO
Newbie
 
Join Date: Nov 2004
Posts: 17
Rep Power: 0 GoO is on a distinguished road
n00b gui program help

ok i said this was a n00b program. im still a beginner in this java gui thing...
what's wrong with this program? it says exception in thread "main". java.lang.nullexception... i cant seem to make this work. i checked the syntax, maybe anyone can help? thanks.

import java.awt.*;

public class ChatClient1 {
	private Frame f1;
	private Panel p1;
	private Button bSend, bQuit, bWhite, bYellow, bBlue;
	private TextArea txtA1;
	private TextField txtF1;
	
	public void ChatClient1() {
		f1 = new Frame("Chat Room");
		p1 = new Panel();
		bSend = new Button("Send");
		bQuit = new Button("Quit");
		bWhite = new Button("White");
		bYellow = new Button("Yellow");
		bBlue = new Button("Blue");
		txtA1 = new TextArea();
		txtF1 = new TextField();
	}
	
	public void launchFrame() {
		f1.add(txtA1, "Center");
		f1.add(txtF1, "South");
		f1.add(p1, "East");
			p1.add(bSend);
			p1.add(bQuit);
			p1.add(bWhite);
			p1.add(bYellow);
			p1.add(bBlue);
		f1.pack();
		f1.setVisible(true);
	}
	
	public static void main(String args[]) {
		ChatClient1 guiWindow = new ChatClient1();
		guiWindow.launchFrame();
	}
}
GoO is offline   Reply With Quote
Old Feb 7th, 2005, 1:33 PM   #2
Dizzutch
Professional Programmer
 
Dizzutch's Avatar
 
Join Date: Dec 2004
Location: Worcester, MA
Posts: 441
Rep Power: 4 Dizzutch is on a distinguished road
Send a message via ICQ to Dizzutch Send a message via AIM to Dizzutch Send a message via MSN to Dizzutch Send a message via Yahoo to Dizzutch
Where are you getting the NullPOinterException? it should give you a line number. When you know that, check all the variables on that line, a NullPointerException gets throws when a variable is accessed that does not point to anything. it points to Null, so make sure all your variables point to something that exists.
good luck
dizz
__________________
naked pictures of you | PFO F@H stats
Dizzutch is offline   Reply With Quote
Old Feb 7th, 2005, 1:36 PM   #3
EdSalamander
Programmer
 
EdSalamander's Avatar
 
Join Date: Dec 2004
Location: Tucson, AZ, USA
Posts: 80
Rep Power: 4 EdSalamander is on a distinguished road
Send a message via AIM to EdSalamander
No worries. Take "void" out of your constructor. It (and all constructors you make) should only have visibilty and a name with no return type. It should read..

public ChatClient1() {
  f1 = new Frame("Chat Room");
  p1 = new Panel();
  etc...
}

The way you have it right now, because it's not a proper constructor, none of those variables are being initialized. When that first add() method is called in launchFrame(), it throws a NullPointerException because the frame f1 doesn't even exist yet (ie, it's still null).
__________________
I can pick my friends. And I can pick my nose. So, why can't I pick my friend's nose?
EdSalamander is offline   Reply With Quote
Old Feb 7th, 2005, 2:57 PM   #4
Dizzutch
Professional Programmer
 
Dizzutch's Avatar
 
Join Date: Dec 2004
Location: Worcester, MA
Posts: 441
Rep Power: 4 Dizzutch is on a distinguished road
Send a message via ICQ to Dizzutch Send a message via AIM to Dizzutch Send a message via MSN to Dizzutch Send a message via Yahoo to Dizzutch
ah, i wasn't aware of that. thanks for letting me know that Ed.
__________________
naked pictures of you | PFO F@H stats
Dizzutch is offline   Reply With Quote
Old Feb 7th, 2005, 6:57 PM   #5
EdSalamander
Programmer
 
EdSalamander's Avatar
 
Join Date: Dec 2004
Location: Tucson, AZ, USA
Posts: 80
Rep Power: 4 EdSalamander is on a distinguished road
Send a message via AIM to EdSalamander
Just doing my part to save the rainforest.
__________________
I can pick my friends. And I can pick my nose. So, why can't I pick my friend's nose?
EdSalamander is offline   Reply With Quote
Old Feb 7th, 2005, 10:02 PM   #6
GoO
Newbie
 
Join Date: Nov 2004
Posts: 17
Rep Power: 0 GoO is on a distinguished road
hey thanks a lot! it worked great.

i just saw a sample code from Sun (java student guide) where the constructor is declared void. so i just followed that. anyway thanks again!
GoO is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 4:39 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC