This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Java in General and the fly likes :(  simple chat client n server.. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark ":(  simple chat client n server.." Watch ":(  simple chat client n server.." New topic
Author

:( simple chat client n server..

simranjit singh
Greenhorn

Joined: Mar 01, 2007
Posts: 12
i am developing a code from headfirst java book from orielly on netbeans..

since d code is huge i cannot type it or copy it here.. so i hv uploaded it on d site..

megaupload
try compiling server.java, login.java, client.java
and running server.java n login.java
d problem i am having is when i try sending message from client d printwriter or my textfiled gives a nullpointer exception.. i hv tried a lot debugging to find wat might b probling but cannot find it..
i will b glad if somebody spends his/her time telling wat d prob is.. i m kinda newbie for java..

netbeans m using is 5.5 n jdk1.6
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6662
    
    5

What is "b" "d" "m" "n" "wat" ? Please use real words. Also please post your stack trace and give us a better high level overview of your problem to receive better responses


SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14278
    
  21

Where do you see the NullPointerException? Look carefully at the error message and the stack trace. It will tell you exactly in which line of code in which source file the exception happens.

Lookup that line in your source code. Something there is null when it shouldn't be. Find out why that is so and solve the problem.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
simranjit singh
Greenhorn

Joined: Mar 01, 2007
Posts: 12
java.lang.NullPointerException
at chat.Client.jButton1ActionPerformed(Client.java:131)
at chat.Client.access$000(Client.java:20)
at chat.Client$1.actionPerformed(Client.java:73)
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:6038)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3260)
at java.awt.Component.processEvent(Component.java:5803)
at java.awt.Container.processEvent(Container.java:2058)
at java.awt.Component.dispatchEventImpl(Component.java:4410)
at java.awt.Container.dispatchEventImpl(Container.java:2116)
at java.awt.Component.dispatchEvent(Component.java:4240)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4322)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3986)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3916)
at java.awt.Container.dispatchEventImpl(Container.java:2102)
at java.awt.Window.dispatchEventImpl(Window.java:2429)
at java.awt.Component.dispatchEvent(Component.java:4240)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)
simranjit singh
Greenhorn

Joined: Mar 01, 2007
Posts: 12
this above is the stack trace as requested..
the problem is the code for the jtextfield is all self generated by netbeans ide and i am not able to find out why it is showing me nullpointer
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

According to the stack trace it's happening in Client.java at line 131. Something on the left hand side of a dot or a "[" is null. Whatever fits this description on this line must be null, so find out why it is.


[Jess in Action][AskingGoodQuestions]
simranjit singh
Greenhorn

Joined: Mar 01, 2007
Posts: 12
this i also know..
if i wz able to find the error, why wud i post it here..
i dont know why is it giving error, according to me code is fine..

[ March 02, 2007: Message edited by: simranjit singh ]

[Andrew: removed swearing.]
[ March 02, 2007: Message edited by: Andrew Monkhouse ]
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18914
    
  40

Originally posted by simranjit singh:
this i also know..
if i wz able to find the error, why wud i post it here..
i dont know why is it giving error, according to me code is fine..


What do you mean by "according to me code is fine"? What did you look at?

Bring up netbeans, load up client.java, and go to line 131. At this point, either...

(1) bring up the netbeans debugger, place a breakpoint just before line 131. run it to the breakpoint. and trace it til you get the exception. or...

(2) place a System.out.print() just before and after where the error is happening, printing out variables being used. After a couple of runs, you should be able to isolate the exact line and variable causing it.


Don't assume that you found the error... if you don't know why it is happening, you haven't found the error.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11441
    
  16

according to me code is fine

Well, if according to YOU it's fine, then why are we having this discussion?

OH, that's right. Because your code is NOT fine. That is what the exception is telling you.

if i wz able to find the error, why wud i post it here..


I'm not sure what all these terms mean... "wz" is not a word, nor is "wud". But if you mean what i THINK you mean, the answer is to get help. To learn. to get guidance.

If you think we are here to do you work for you, you are wrong. We try and teach people how to solve their problems, and how to think about things.

Both Henry and Ernest have give you suggestions on where to start. Follow their advice, and if you get stuck, come back with what you have found, and ask a new question.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
 
jQuery in Action, 2nd edition
 
subject: :( simple chat client n server..