This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Java exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Java exception" Watch "Java exception" New topic
Author

Java exception

Oomeh Khima
Greenhorn

Joined: Jun 08, 2008
Posts: 2
hello
I have a quiz system that has a server, a player and a friend client. I have tried running them( by directly running their main classes) it works fine.

However when i load a player and a friend client from an interface by clicking on their respective jButton, the respective interfaces are loaded but i get the following error:

Exception in thread "Thread-3" java.lang.NullPointerException
at playerQuiz.src.QuizClient.run(QuizClient.java:318)
at java.lang.Thread.run(Thread.java:595)

But as i have already mentioned the program works perfectly when not loaded from a button.

The code at line 318:



The complete class QuizClient :
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41089
    
  44
Welcome to JavaRanch.

That's too much code to work through all of it, but keep in mind that the code in the main method is executed only if it is run from the command line. So if the "in" and "out" streams are not initialized anywhere else, they will be null if the code is not run from the command line.


Ping & DNS - my free Android networking tools app
Oomeh Khima
Greenhorn

Joined: Jun 08, 2008
Posts: 2
Thank you for your reply. Where should the "in" and "out" be initialzed and to what, so that they will be null if the code is not run from the command line but from GUI.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41089
    
  44
Either initialize everything directly in the constructor, or move it into an "init()" method that's called after the constructor is done.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java exception
 
Similar Threads
Help with Chat software
writeUTF and JComboBox
Errors in GUI program
What's up with a random number like this being displayed 889193265?
Transforming Code