Jump to content

Timer NullPointException

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
2 replies to this topic

#1
domestic

domestic

    Learning Programmer

  • Members
  • PipPipPip
  • 44 posts
Hey. Im building this J2ME app. Basically, its an alarm, but I got a problem.

I set the alarm and everything and it works perfect, except that the timer never works and I don't know why.

        long now = new Date().getTime();
        stringItem3 = new StringItem(alarmDate.toString(), null);

        System.out.println(alarmDate.getTime() - now);

        long amount = alarmDate.getTime() - now;
        alarmTimer.schedule(at, amount); //error here
        System.out.println("im here");
    }

    class Alarmer extends TimerTask {

        public void run() {
            System.out.println("i run");
        }
    }
Everytime though, it reaches the alarmTimer.schedule and throws this error:

TRACE: <at java.lang.NullPointerException:   0>, Exception caught in Display class
java.lang.NullPointerException:   0
        at VisualMIDlet.doAlarm(VisualMIDlet.java:510)
        at VisualMIDlet.commandAction(VisualMIDlet.java:189)
        at javax.microedition.lcdui.Display$ChameleonTunnel.callScreenListener(), bci=46
        at com.sun.midp.chameleon.layers.SoftButtonLayer.processCommand(), bci=74
        at com.sun.midp.chameleon.layers.SoftButtonLayer.soft1(), bci=37
        at com.sun.midp.chameleon.layers.SoftButtonLayer.softPress(), bci=29
        at com.sun.midp.chameleon.layers.SoftButtonLayer.pointerInput(), bci=142
        at com.sun.midp.chameleon.CWindow.pointerInput(), bci=76
        at javax.microedition.lcdui.Display$DisplayEventConsumerImpl.handlePointerEvent(), bci=19
        at com.sun.midp.lcdui.DisplayEventListener.process(), bci=296
        at com.sun.midp.events.EventQueue.run(), bci=179
        at java.lang.Thread.run(Thread.java:619)
510 is the alarmTimer.schedule line. Any ideas? Please.
.
Posted Image

Programming Languages: Java, VB6, VB2005 (.NET2)
Web Languages: HTML, CSS, JS

Website: http://abdn.ac.uk/~u41am6

Opportunity is missed by most people because it is dressed in overalls and looks like work.

#2
ZekeDragon

ZekeDragon

    Writes binary right handed and hex left handed

  • Moderators
  • 2,103 posts
You don't show where you initialize the Alarmer object as the name "at", which seems to be the problem. If "at" is not initialized, or for some other reason is NULL, you'll get that exception.
Wow I changed my sig!

#3
domestic

domestic

    Learning Programmer

  • Members
  • PipPipPip
  • 44 posts
Woops. Forgot to initialise either timer... Dam. My bad! Cheers mate.
.
Posted Image

Programming Languages: Java, VB6, VB2005 (.NET2)
Web Languages: HTML, CSS, JS

Website: http://abdn.ac.uk/~u41am6

Opportunity is missed by most people because it is dressed in overalls and looks like work.