Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java exception

 
Oomeh Khima
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Oomeh Khima
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Either initialize everything directly in the constructor, or move it into an "init()" method that's called after the constructor is done.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic