This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
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..
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)
Joined: Mar 01, 2007
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
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.
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.