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


LCD Digital Multimeter Voltmeter Ammeter Ohmmeter Volt AC DC Tester Leads Meter picture

LCD Digital Multimeter Voltmeter Ammeter Ohmmeter Volt AC DC Tester Leads Meter

$9.95



DC 100V 100A Voltmeter Ammeter Volt Amp Meter Voltage Current Tester with Shunt picture

DC 100V 100A Voltmeter Ammeter Volt Amp Meter Voltage Current Tester with Shunt

$12.74



US Stock DC -100A ~ +100A Analog AMP Current Needle Panel Meter Ammeter & Shunt picture

US Stock DC -100A ~ +100A Analog AMP Current Needle Panel Meter Ammeter & Shunt

$30.47



DC 100A 100V Voltmeter Ammeter Volt Amp Meter Voltage Current Tester with Shunt picture

DC 100A 100V Voltmeter Ammeter Volt Amp Meter Voltage Current Tester with Shunt

$12.99



LCD Digital Multimeter Voltmeter Ammeter Ohmmeter Volt AC DC Tester Leads Meter picture

LCD Digital Multimeter Voltmeter Ammeter Ohmmeter Volt AC DC Tester Leads Meter

$7.49



US Stock DC 0~30A Analog AMP Current Pointer Needle Panel Meter Ammeter & Shunt picture

US Stock DC 0~30A Analog AMP Current Pointer Needle Panel Meter Ammeter & Shunt

$18.22







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