• Post Reply Bookmark Topic Watch Topic
  • New Topic

What is causing the Exception in thread “pool-1-thread-2” (NullPointerException)  RSS feed

 
Josef Lundström
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I  am creating a multi-threaded web server. When I run the client I receive a NullPointException. Why is this happening and what can be done to solve it?

Here you can read exception message and the stack trace:



Here I am initializing the Executor which are handling the threads:



The origin of the String questions[1] is in the Broadcaster class:

I am using a get and set method to make it possible for the other inner class to work with



Here are the Strings and created:




The NullPointerException occurs in the HandleValidation class:


class HandlleValidation extends Thread {

The problem is caused by this line:



The Setter:



I have tried to include as little of the code as possible to describe the problem. I may be able to give more information if requested!
 
Norm Radder
Rancher
Posts: 2240
28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Basically with NPE you look at the line where it happened, find the variable with the null value and then backtrack in the code to see why that variable is null.
 
H Paul
Ranch Hand
Posts: 491
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you can not troubleshoot the logic/flow of your App by just reading the code as Norm sugested,
then use the IDE debugger:
1. run QuizServer in debug mode
2. For example:  set a breakpoint at the line where NPE occured: line 121 in HandleValidation class.

See the exception you posted:



(A side note: I learned many things by using a debugger :-D)
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!