Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
Posts: 132
Registered: ‎10-25-2011
My Device: Tour 9630
My Carrier: MTN
Accepted Solution

Blackberry SDCard access from main class

Good day , Please i have an issue with accessing the sd card in my main class , basically i can access the sd card but not from my main class , a screen must be displayed with a button to navigate me to the screen with the database access , please can someone explain why it  is so ?

Contributor
Posts: 27
Registered: ‎02-12-2010
My Device: Torch 9800
My Carrier: Globe/Unlocked AT&T

Re: Blackberry SDCard access from main class

Where did you put the code for accessing the SD Card? Is it in the main() method before you initialize your app? I guess that's because it has not initialized/entered the event dispatcher yet.

 

I don't think you have to push a screen to the display stack to access the SD Card but you need to make sure you have initialized your Application/UiApplication first.

Developer
Posts: 132
Registered: ‎10-25-2011
My Device: Tour 9630
My Carrier: MTN

Re: Blackberry SDCard access from main class

Its in the constructor of my main class such as
Public class zoom
{
Public zoom()
{
Sd card initialization code


}


}So I get the error from the constructor
Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Blackberry SDCard access from main class

Don't put the SD Card accessing code in main.  Put it in some initialization code that runs after your UiApplication has been created.

 

You might find this useful, it can be used even if your application is not auto-started. 

http://supportforums.blackberry.com/t5/Java-Development/Write-safe-initialization-code/ta-p/444795

Developer
Posts: 132
Registered: ‎10-25-2011
My Device: Tour 9630
My Carrier: MTN

Re: Blackberry SDCard access from main class

I have tried to do this ,  still get the same issues 

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Blackberry SDCard access from main class

What error are you seeing?  What line is it on?  Can you show us the code that is failing?  Does this happen on a SImulator or device?

Developer
Posts: 132
Registered: ‎10-25-2011
My Device: Tour 9630
My Carrier: MTN

Re: Blackberry SDCard access from main class

It happens on a simulator and my 9650 device , I have already created my db and I want to be able to check some parameters before I display a screen
Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Blackberry SDCard access from main class

And the answers to my other questions are....?

Developer
Posts: 132
Registered: ‎10-25-2011
My Device: Tour 9630
My Carrier: MTN

Re: Blackberry SDCard access from main class

The truth peter is this , I had to create another screen that will display a button and the action of that button is to do the sd card access , it is clear that I can't access my sdcard from my main class , thanks .
Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Blackberry SDCard access from main class

If you have solved this some other way then can you mark this as solved?

 

Coded correctly, there should be no problem accessing the SD Card before displaying a screen. 

 

If you don't want to try moving the code into a startup processing that is initiated after your Application is created, then that is OK.  But if you want us to help you do this, then I suggest you rework your main so that the SD Card access is not started until your Application has been created and has entered dispatching. 

 

Referencing the KB article I pointed you at, the key part to that is:

invokeLater(new Runnable() {
            public void run() {
                doStartupWork();
            }
        });

You will put the code to do the SD Card access in this and you will put your push for your Screen in this too. 

 

But if you are happy with what you currently have, please mark this as solved.