Re: problem in thread when calling a class member's method



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.
.



Relevant Pages

  • Re: Keine VCL Objekte aus Thread heraus manipulieren
    ... Wenn 4 mal pro Sekunde nur ein Progresswert (Member, Integer) ... nur ein mal pro Zeitabschnitt die GUI aktualisiert. ... Das Problem der vielen Nachrichten ist gar keins. ...
    (de.comp.lang.delphi.misc)
  • Avoiding rtti
    ... the member data of classes derived from my base class. ... Simulations call addParameteron their data and the GUI works by keeping ... These pointers (along with other data to be displayed ...
    (comp.lang.cpp)
  • Re: Updating display of Tree Control with check boxes
    ... // look for the next member item ... // let the GUI have a chance to catch up ... stepping in and making sure that SetCheck is being called. ...
    (microsoft.public.vc.mfc)
  • [Winforms C++] - Design a GUI with multiple Winforms
    ... I'm designing a GUI based on Winforms under Visual Studio .net. ... I have a main frame who instanciate the ... strange because my Intellisense show me the form1 as a member of GUI ...
    (microsoft.public.dotnet.framework.windowsforms)