Solved

end of a thread's execution throws java.lang.NullPointerException

Posted on 2006-11-18
4
204 Views
Last Modified: 2010-03-31
Hi,

I made an application, call it a.java, that creates 2 thread objects, call them t1 and t2.   t1 and t2 each use a parser object to parse an xml file.  a.java creates the two parser objects, call them p1 and p2, and passes them to t1, and t2, respectively. There is no "communication" between the parser objects and a.java object.
When one of the threads finishes, the other thread dies. The error I get is
Exception in thread "Thread-2" java.lang.NullPointerException
        at iroom.xmlp.process(xmlp.java:153)
        at iroom.xmlp.parse(xmlp.java:87)
        at iroom.ParserRunner.run(ParserRunner.java:29)
        at java.lang.Thread.run(Thread.java:595)
 where iroom is the package, xmlp is the parser class from which p1 and p2 are instantiated, and ParserRunner is the class from which t1 and t2 are instatiated, and it implements Runnable interface.
When I only create one thread the program finishes without any errors.
I am new to threads in Java, and would appreciate any help in solving this problem.

Mirna
0
Comment
Question by:mirnalim
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 

Author Comment

by:mirnalim
ID: 17973501
I forgot to add that a.java creates two instances of a third class, Tag, call them tag1 and tag2, and gives tag1 to t1, and tag2 to t2. Since each thread receives its own copy of the xmlp object and Tag object I do not synchronize any of the calls.
0
 
LVL 23

Expert Comment

by:Ajay-Singh
ID: 17973525
can you post process method? (line no 153)
0
 

Author Comment

by:mirnalim
ID: 17973527
I just found out that when one of the theads finishes execution the control is given back to the main function in a.java instance, which then exist and this throws the null pointer exception. So how do I make the main function wait until all of the threads are finished executing?
0
 
LVL 23

Accepted Solution

by:
Ajay-Singh earned 500 total points
ID: 17973538
call join()

t1.join();
t2.join();
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to implement Singleton Design Pattern in Java.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question