Solved

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

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Receive file in Servlet 1 36
countX 22 70
network + 7 73
firstChar challenge 13 83
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This video teaches viewers about errors in exception handling.

707 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now