BlackBerry Forums Support Community
              

Closed Thread
 
Thread Tools
Old 10-28-2008, 10:19 PM   #1
toscaty
New Member
 
Join Date: Oct 2008
Model: 8800
PIN: N/A
Carrier: rogers
Posts: 11
Default Thread is null elsewhere in same class

Please Login to Remove!

I have a thread that sleeps and then repaints the main screen. I launch the thread in the main screen class and i can then use getname to avoid relaunching, but in other places in the same class i get a null for the Thread??
Code:
class MainWindow extends MainScreen
{
    private Font myfont;
    private MyThread thread1;
    MainWindow() {
        
        super();
 
        
        String thn = Thread.currentThread().getName();
        if (thn == "scrpaint") 
        {
        }
        else 
        {
        MyThread thread1 = new MyThread ("scrpaint");
        System.out.println("Thread 1: "+ thread1.t.isAlive());
        System.out.println("Thread name is " + thread1.t.getName());
        }
but 5 lines down if I try to get the Thread name using

System.out.println("Thread name is " + thread1.t.getName());

- the Thread is Null?? and my app throws a null pointer exception
Any ideas why? I want to interrupt the thread and display another screen and then resume...
Offline  
Old 10-29-2008, 01:21 AM   #2
nanika
Knows Where the Search Button Is
 
Join Date: Mar 2008
Location: Paris, France
Model: None
PIN: N/A
Carrier: None
Posts: 36
Default

Apparently, you mask your thread1 member with a variable local to the constructor. The former is never set.

Last edited by nanika; 10-29-2008 at 07:28 AM..
Offline  
Old 10-29-2008, 09:50 AM   #3
toscaty
New Member
 
Join Date: Oct 2008
Model: 8800
PIN: N/A
Carrier: rogers
Posts: 11
Default

I am not sure that I follow what you mean? Can you describe in laymans terms what you mean? what am I masking the thread with ?
Offline  
Old 10-29-2008, 10:41 AM   #4
CELITE
Thumbs Must Hurt
 
Join Date: Dec 2005
Model: 8310
Carrier: Rogers
Posts: 138
Default

Could you show us the implementation of MyThread?
Offline  
Old 10-29-2008, 11:24 AM   #5
toscaty
New Member
 
Join Date: Oct 2008
Model: 8800
PIN: N/A
Carrier: rogers
Posts: 11
Default My Thread

Sure

Here it is

Code:
class MyThread implements Runnable {
  String tName;
  Thread t;
  MyThread (String threadName) {
     tName = threadName;
     t = new Thread (this, tName);
     t.start();
  }
  public void run() {
     for (int i = 0; i < 100; i++)
              {
     try {
            System.out.println("Thread: " + tName ); 
            
            synchronized  (Application.getEventLock()){
                     Screen cursc =   UiApplication.getUiApplication().getActiveScreen();
                     System.out.println(cursc);
                     
                    UiApplication.getUiApplication().pushScreen(new MainWindow());
                    }
            Thread.sleep(5000);
          } 
          catch (InterruptedException e ) {}

     System.out.println("End of Thread running" );
               }
          }
   
}
Offline  
Old 10-29-2008, 05:46 PM   #6
toscaty
New Member
 
Join Date: Oct 2008
Model: 8800
PIN: N/A
Carrier: rogers
Posts: 11
Default Thread handle

Well I have to say that getting control and access to threads in the JVM is a major pain. I resorted in the end to leaving the thread and not trying to stop or access it but within its try I set a while(boolean) then set the value of the boolean in other screens to stop the Thread running or processing rather, seems to work quite well - this link was a help

156939-thread-null-elsewhere-same-class.html

I dont understand why there is no stop method or kill method
Offline  
Old 10-30-2008, 03:51 AM   #7
simon.hain
CrackBerry Addict
 
Join Date: Apr 2005
Location: hamburg, germany
Model: 8900
Carrier: o2
Posts: 838
Default

see this link for an explaination of your initial problem.
remove the re-declaration from the following line
Code:
MyThread thread1 = new MyThread ("scrpaint");
__________________
java developer, Devinto, hamburg/germany
Offline  
Closed Thread



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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


APPLE 630-0895-B  VRAM 128K X 8 BOARD CARD VINTAGE picture

APPLE 630-0895-B VRAM 128K X 8 BOARD CARD VINTAGE

$74.77



APPLE 820-0522-A 630-0895-B LITE VRAM 128K X 8 BOARD  picture

APPLE 820-0522-A 630-0895-B LITE VRAM 128K X 8 BOARD

$149.99



128K RAM - APPLE - ORIGINAL APPLE prototype BOARD picture

128K RAM - APPLE - ORIGINAL APPLE prototype BOARD

$408.75







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