Are you actually creating the class in question?  Maybe it isn't getting
constructed and so neither is the timer? BTW: I would highly recommend
only creating Timers in the Application.java file. I've created NSTimers
in basically the same way you are here and they just worked. But I
created them in my Application constructor.  One tip: when creating the
NSSelector use the class of the target object:

        Class[] classes = {this.getClass()};
        NSSelector aSel = new NSSelector("secondElapsed", classes);

Another tip: when passing a run loop run mode, use the Class variables
like this instead of from the instance:

NSRunLoop.DefaultRunLoopMode

like

theLoop.addTimerForMode(theTimer, NSRunLoop.DefaultRunLoopMode);
     

d


Leon Amdour wrote:
> 
> I'm sorry, but I have to return to my earlier question about NSTimer. I've
> received some suggestions and they helped me to move forward. But what I've
> done so far doesn't work. Here's what I have:
> 
>     public MyClass() {
>         super();
> 
>         ...
> 
>         NSRunLoop theLoop = NSRunLoop.currentRunLoop();
>         NSSelector
> aSel = new NSSelector("secondElapsed", new Class[] {Object.class});
> 
> NSTimer theTimer = new NSTimer(1.0, this, aSel, null, true);
> 
> theLoop.addTimerForMode(theTimer, theLoop.DefaultRunLoopMode);
>     }
> 
>     public void secondElapsed(NSTimer theTimer) {
>         ...
>     }
> 
> (I also tried 'new NSSelector("secondElapsed", null)').
> 
> It, sure, passes compilation, but secondElapsed doesn't seem to get called.
> Am I missing something? I assume, addTimerForMode is necessary... or should
> I do something else or differently?
> 
> And while I'm at it, I have another, general question. I cannot check
> variables in the debugger. Even though I build "debug" target and run it in
> debugger mode, every time I stop, select a variable and click any of the
> Print Value buttons in the Launch window I get things like:
> JavaDebug>> print theTimer
> "theTimer" is not a valid local or class name.
> JavaDebug>> print * theTimer
> "*" is not a valid local or class name.
> "theTimer" is not a valid local or class name.
> JavaDebug>> po theTimer
> "theTimer" is not a valid local or class name.
> 
> (As you understand I'm using Java).
> 
> Any ideas? Help would be greatly appreciated. Thanks a lot.
> 
> Leon

Reply via email to