BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 10-28-2008, 11:19 PM   #1 (permalink)
New Member
 
Join Date: Oct 2008
Model: 8800
PIN: N/A
Carrier: rogers
Posts: 11
Post Thanks: 0
Thanked 0 Times in 0 Posts
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, 02:21 AM   #2 (permalink)
Knows Where the Search Button Is
 
Join Date: Mar 2008
Location: Paris, France
Model: None
PIN: N/A
Carrier: None
Posts: 36
Post Thanks: 0
Thanked 0 Times in 0 Posts
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 08:28 AM.
Offline  
Old 10-29-2008, 10:50 AM   #3 (permalink)
New Member
 
Join Date: Oct 2008
Model: 8800
PIN: N/A
Carrier: rogers
Posts: 11
Post Thanks: 0
Thanked 0 Times in 0 Posts
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, 11:41 AM   #4 (permalink)
Thumbs Must Hurt
 
Join Date: Dec 2005
Model: 8310
Carrier: Rogers
Posts: 138
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Could you show us the implementation of MyThread?
Offline  
Old 10-29-2008, 12:24 PM   #5 (permalink)
New Member
 
Join Date: Oct 2008
Model: 8800
PIN: N/A
Carrier: rogers
Posts: 11
Post Thanks: 0
Thanked 0 Times in 0 Posts
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, 06:46 PM   #6 (permalink)
New Member
 
Join Date: Oct 2008
Model: 8800
PIN: N/A
Carrier: rogers
Posts: 11
Post Thanks: 0
Thanked 0 Times in 0 Posts
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, 04:51 AM   #7 (permalink)
CrackBerry Addict
 
Join Date: Apr 2005
Location: hamburg, germany
Model: 8900
Carrier: o2
Posts: 838
Post Thanks: 0
Thanked 0 Times in 0 Posts
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


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





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