BlackBerry Forums Support Community
              

Closed Thread
 
LinkBack Thread Tools
Old 05-03-2007, 05:27 AM   #1 (permalink)
Thumbs Must Hurt
 
Join Date: May 2007
Location: berlin, germany
Model: 8310
PIN: N/A
Carrier: vodafone
Posts: 163
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default exception in timer thread

Please Login to Remove!

hi,
i tried to create a simple thread which updates every 5 seconds the status auf the batterie.
now I have this little piece of code:
Code:
TimerTask worker = new TimerTask();
        worker.run();
/*
...
*/
final class TimerTask extends Thread  {
       LabelField label1 = new LabelField("Batteriestand: wird ermittelt...");
       public TimerTask()
        {      
        }
        public void run() {
            add(label1);
            int temp = DeviceInfo.getBatteryLevel();
            String a;
            a = "" + temp;
            this.label1.setText("Batteriestand: "+a);
            while(true) {
                try {
                    Thread.sleep(5000);
                     int temp2 = DeviceInfo.getBatteryLevel();
                     String b;
                     b = "" + temp2;
                     System.out.println("Batteriestand: "+b);
                     this.label1.setText("Batteriestand: "+b);
                } catch( InterruptedException e ) {
                    System.out.println(e.toString());
                    System.err.println(e.toString());
                }
             }
        }
    }
i know it isn't the perfect code, but i'm still a beginner ;)
when I try this little "program" on the simulator it works fine, but when I try this one on my BlackBerry I get an error-message by the debugger:
Quote:
Uncaught exception thrown - Cannot determine object class. Missing debug information.
when I comment the line this.label1.setText("Batteriestand: "+b); then the debugger does not throw out an error.

so how can I update the LabelField Text without an exception error?

hibbert
Offline  
Old 05-04-2007, 01:43 AM   #2 (permalink)
Talking BlackBerry Encyclopedia
 
Skipper_Joe's Avatar
 
Join Date: Jan 2007
Location: Kharkov, Ukraine
Model: 8300
Carrier: N/A
Posts: 237
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

You don't post exception itself, but it looks like you try to modify UI not in UI-event thread. Wrap your code in anonymous Runnable class and use Application.invokeLater() or Application.invokeAndWait() methods:

Code:
_application.invokeLater(new Runnable()
{
    public void run()
    {
        label1.setText("Batteriestand: "+a);
    }
});
Offline  
Old 05-04-2007, 02:41 AM   #3 (permalink)
Thumbs Must Hurt
 
Join Date: May 2007
Location: berlin, germany
Model: 8310
PIN: N/A
Carrier: vodafone
Posts: 163
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

hi,
thanks for the reply. The BB doesn't show an Exception, i can read it just in the Debugger ( Uncaught exception thrown - Cannot determine object class. Missing debug information.)

ok now i have a new problem:
where do i have to put the invokeLater? and what should i use instead of _application?
Code:
final class TimerTask extends Thread  {
       LabelField label1 = new LabelField("Batteriestand: wird ermittelt...");
       public TimerTask()
        {
        
        }
        public void setText(String text) {
                      LabelField label1 = this.label1;
                      label1.setText(text);
                    }
        public void run() {
            add(label1);
            int temp = DeviceInfo.getBatteryLevel();
            String a;
            a = "" + temp;
            this.label1.setText("Batteriestand: "+a);
            while(true) {
                try {
                    sleep(5000);
                     
                } catch( InterruptedException e ) {
                invokeLater(new Runnable(){
                public void run() {
                label1.setText("Batteriestand: "+System.currentTimeMillis());
                }
                });
                    System.out.println(e.toString());
                    System.err.println(e.toString());
                }
                System.out.println(DeviceInfo.getDeviceName()+" Meldet sich:");
                
                int temp2 = DeviceInfo.getBatteryLevel();
                String b;
                b = "Batteriestand ("+System.currentTimeMillis()+"): "+temp2;
                System.out.println(b);
              // just refresh the LabelField on the BB 7230, because there it works ;)
                // aktualisierung nur bei BB 7230 !!
                String model;
                model = DeviceInfo.getDeviceName();
                if (model.equalsIgnoreCase("7230")){
                    System.out.println("Aktualisiere Ausgabe... ("+DeviceInfo.getDeviceName()+")");
                    setText(b);
                    setText2(txt);
                    this.label3.setText(dater);
                }
             }
            
        }
    }
sry i'm really a newbie
it would be nice if you can help me one again.

thanks so far. hibbert

//edit
ok i used the forum search function and i found a solution for my problem. now it works ;)

thanks for your help

Last edited by hibbert : 05-04-2007 at 03:08 AM. Reason: solution found
Offline  
Closed Thread


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Dell CW796 Cover Top 1720 OEM Genuine NIB OEM
$39.95
Dell CW796 Cover Top 1720 OEM Genuine NIB OEM  pictureDELL 725-10263 / 331-1310 / KT74N Lamp manufactured by DELL
$195.86
DELL 725-10263 / 331-1310 / KT74N Lamp manufactured by DELL pictureOEM Dell 0PH344 375W PSU N375P-00 NPS-375AB A Power Supply for Precision 380 390
$22.98
OEM Dell 0PH344 375W PSU N375P-00 NPS-375AB A Power Supply for Precision 380 390 pictureNew Dell Genuine OEM Cyan Toner Cartridge H625 H825 S2825 P3HJK
$75.98
New Dell Genuine OEM Cyan Toner Cartridge H625 H825 S2825 P3HJK  pictureOriginal Chunghwa 15" CLAA150XP01QL A+ LCD Screen Display OEM Dell E157FPTe
$45.0
Original Chunghwa 15






Copyright 2004-2016 BlackBerryForums.com.
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.