?
Solved

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

Posted on 2006-11-18
4
Medium Priority
?
216 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 2000 total points
ID: 17973538
call join()

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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
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 will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month8 days, 13 hours left to enroll

765 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