Solved

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

Posted on 2006-11-18
4
212 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
In this post we will learn different types of Android Layout and some basics of an Android App.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

726 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