BlackBerry Forums Support Community
              

Closed Thread
 
Thread Tools
Old 06-06-2008, 05:02 AM   #1
ilh3-
Knows Where the Search Button Is
 
Join Date: Mar 2008
Model: 8300
PIN: N/A
Carrier: O2
Posts: 17
Default static data is null from external event

Please Login to Remove!

Hello all,

I have a program that has some static data and auto-runs on startup so that the static data is created (including a reference to the instance of the program). I also create a phone listener and add it so that when a call is disconnected it fires. My phone listener upon disconnecting puts up a new screen which uses the static data but the problem is it sees it all as null and so breaks saying the application is already running in this process.
I use exactly the same code for the creation of the screen to access the screen manually from the ribbon and it works perfectly fine.

It's not just the phone listener either, i've tried the phonelog listener and the same story.

Here's the jist of my code

Code:
public class Program extends UiApplication
{
    private static Program _instance = null;
    private static Model _model;

    public static Program getInstance()
    {
        if (_instance == null)
            _instance = new Program();
        return _instance;
    }

    private Program()
    {
        _model = new Model();

        PhoneLogs.addListener(new MyPhoneLogListener());
    }

    public static getModel()
    {
        return _model;
    }

    public static void main(String[] args)
    {
        Program.getInstance().enterEventDispatcher();
    }



    class MyPhoneLogListener implements PhoneLogListener
    {
        public void callLogAdded(CallLog cl)
        {
            UiApplication.getUiApplication().pushScreen(new MyScreen());
        }
        
        public void callLogRemoved(CallLog cl)
        {
        }
        
        public void callLogUpdated(CallLog cl, CallLog oldCl)
        {
        }
        
        public void reset()
        {
        }
    }
}
Code:
class MyScreen extends MainScreen
{
    Model _model;

    public MyScreen()
    {
        super();
        
        _model = Program.getModel();
        // breaks here as it thinks that _instance in Program is null (even though
        // it's already been created and it's static) and so tries to create it again
        // then throws the error that the application already exists in this process
    }
}
Anyone have any idea why this is happening?

Last edited by ilh3-; 06-06-2008 at 05:16 AM..
Offline  
Old 06-06-2008, 06:00 AM   #2
simon.hain
CrackBerry Addict
 
Join Date: Apr 2005
Location: hamburg, germany
Model: 8900
Carrier: o2
Posts: 838
Default

where is your autostart part?
__________________
java developer, Devinto, hamburg/germany
Offline  
Old 06-06-2008, 10:59 AM   #3
ilh3-
Knows Where the Search Button Is
 
Join Date: Mar 2008
Model: 8300
PIN: N/A
Carrier: O2
Posts: 17
Default

Main is the autostart part so it creates an instance of Program (as it's initially null), creates the Model and adds the listener to the PhoneLog.
Then somewhere down the line after a phone call, a log is added to the phonelog which fires an event and callLogAdded is called in the listener. This creates a MyScreen which accesses the Model in the Program class and should see the original Model created at the start as it's static but it sees it as null.
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


BISSELL 3-in-1 Turbo Lightweight Stick Vacuum, 2610 (Black) picture

BISSELL 3-in-1 Turbo Lightweight Stick Vacuum, 2610 (Black)

$36.06



Cordless Vacuum Cleaner Stick Handheld for Carpet Pet Hair & Wood Floor Bagless picture

Cordless Vacuum Cleaner Stick Handheld for Carpet Pet Hair & Wood Floor Bagless

$82.85



Shop Vacuum upholstery extractor conversion kit auto vac detail carpet or home.  picture

Shop Vacuum upholstery extractor conversion kit auto vac detail carpet or home.

$220.00



Car Vacuum Cleaner Handheld Vacuum Cordless Portable 18000PA Strong Suction picture

Car Vacuum Cleaner Handheld Vacuum Cordless Portable 18000PA Strong Suction

$59.99



3 CFM Air Vacuum Pump HVAC Manifold Gauge Set AC A/C Refrigeration Kit picture

3 CFM Air Vacuum Pump HVAC Manifold Gauge Set AC A/C Refrigeration Kit

$46.16



Handheld Vacuum Cordless, Powerful Suction Wet Dry Vacuum for Car picture

Handheld Vacuum Cordless, Powerful Suction Wet Dry Vacuum for Car

$40.62







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