• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

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

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Rancher
Posts: 5117
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 491
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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)
 
reply
    Bookmark Topic Watch Topic
  • New Topic