Re: problem in thread when calling a class member's method
- From: "A. Bolmarcich" <aggedor@xxxxxxxxxxxxxxxxxxxx>
- Date: Fri, 28 Apr 2006 23:32:15 -0000
On 2006-04-28, oleth <oleth5962@xxxxxxxx> wrote:
Hello
I have a problem when runing a thread. I have a gui application with a
menu and a menu item. The application extends JPanel and implements
ActionListener. It has several members and one specific member called
lets say "arrow1" which causes he problem. This member is an inner
class instance of a class called "ClassToCall". This class has a method
called "foo" which does nothing but write something to Sytem.out. This
arrow1.foo is called from inside run(). I get the following:
Exception in thread "Thread-2" java.lang.NullPointerException
at MyProblem$InnerThread.run(MyProblem.java:157)
at java.lang.Thread.run(Unknown Source)
In order to replicate the problem try to build the code I have below
and when gui begins click Tranformations -> tranformationA and you get
the problem.
My major problem is I can't figure out why this is hapening and where
to start from
Any directions or ideas?
The arrow1 variable used by the run method is null because a value
is never assigned to it. The arrow1 variable used by the the run
method is the private instance variable of the class MyProblem.
The program contains the statement
ClassToCall arrow1 = new ClassToCall();
at the end of the MyProblem constructor. However, that declares and
initalizes an arrow1 variable that is local to that constructor.
Chances are you want to replace that statement with
arrow1 = new ClassToCall();
which assigns to the arrow1 variable the arrow1 variable used in the
run method.
.
- Follow-Ups:
- References:
- Prev by Date: problem in thread when calling a class member's method
- Next by Date: Re: Updating from PointBase to Derby
- Previous by thread: problem in thread when calling a class member's method
- Next by thread: Re: problem in thread when calling a class member's method
- Index(es):
Relevant Pages
|