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
Super Contributor
bh1r1th
Posts: 273
Registered: ‎11-23-2010
My Device: 9800 torch
Accepted Solution

Null Pointer exception while startup on Application.

[ Edited ]

Hi There,

i have a small problem that come at the after installation of my application when i press my application icon it says Null pointer exception it comes first time only next time onwards it's working perfectly alright. i don't know why this exception came. after installation i am taking into loginscreen of my application. here i am loading Images. and i found some images are returning null. that path is correct and afterthrowing thiswhen i press ok in that exception dialog box and next time i try to lanch the app it's working fine it won't say any exception.

 

 

Please anyone help me.

 

Thank you in advance.

Contributor
smathis
Posts: 21
Registered: ‎01-17-2012
My Device: BlackBerry 9550

Re: Null Pointer exception while startup on homescreen.

Maybe you are using files on the SDCard which is not mounted immediatly when you launch the simulator (the simulator start the application before load the sdcard)

 

You can use this function to see if a sdcard is here.

 

	public static boolean isSDCardAvailable()
	{
		boolean res = false;
    	String root = null;
    	Enumeration e = FileSystemRegistry.listRoots();
    	while (e.hasMoreElements()) 
    	{
    	     root = (String) e.nextElement();
    	     if( root.equalsIgnoreCase("sdcard/") ) 
    	     {
    	        res = true;
    	     } 
    	}
    	
    	return res;
	}

 

You have to use this function, and if it gives you false, push something which wait until the card is mounted.

For instance, this class.

 

public class ScreenNoSDCard extends MainScreen implements FileSystemListener 
{
	public ScreenNoSDCard()
	{
		super();
		add(new LabelField("Cette application fonctionne uniquement avec la présence d'une carte mémoire externe."));
		add(new LabelField("Veuillez insérer une carte mémoire ou quitter l'application."));
		FileSystemRegistry.addFileSystemListener(this);

	}
	
    public void rootChanged(int state, String rootName) 
    {
        if( state == ROOT_ADDED ) 
        {
            if( rootName.equalsIgnoreCase("sdcard/") ) 
            {
                UiApplication.getUiApplication().invokeLater(new Runnable()
                {
                    public void run()
                    {
                    	UiApplication.getUiApplication().popScreen(ScreenNoSDCard.this);
                    	UiApplication.getUiApplication().pushScreen(new ScreenCache());
                    }
                });
            }
        }  
 }
	
}

You won't see this screen, it will be pop before you actually see the application screen.

 

Super Contributor
bh1r1th
Posts: 273
Registered: ‎11-23-2010
My Device: 9800 torch

Re: Null Pointer exception while startup on homescreen.

Thank you smathis,

 

I am not using the files in sd card. in my project placed those images.

In simulator it's working fine.

While on device i am getting this error.

 

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

Re: Null Pointer exception while startup on homescreen.

Does this happen at device startup?  Once the device is started up you should not have any problems with the SD Card.

 

If you are seeing this the first time you run, then install and debug on device, then start you app.  You will get more information about what is going on, and hopefully it will even give you a nice breakpoint. 

Super Contributor
bh1r1th
Posts: 273
Registered: ‎11-23-2010
My Device: 9800 torch

Re: Null Pointer exception while startup on homescreen.

Hi Peter,

Thank you for the replay.

 

I am tried to debug the app at the time of installation before throwing the exception my debug session was closed.

i tried several times. peter but still cann't find the solution. i got this problem after updation of my eclipse. i think this is a build problem?

 

 

Can u please help me?

 

 

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

Re: Null Pointer exception while startup on homescreen.

You haven't answered my question regarding when it happens, I presume it is on installation and NOT at device startup.

 

Do you have any 'autostart' processing?

 

I would next look at the device log (ALT L-G-L-G) and see if there is an entry in there related to the HPE.  I suspect there will be, and it will have the stack trace.  You should be able to track it down from there. 

Super Contributor
bh1r1th
Posts: 273
Registered: ‎11-23-2010
My Device: 9800 torch

Re: Null Pointer exception while startup on homescreen.

After Installation. i got this error Peter.

yes i checked there but here it shows no detail message.and

it gives me some GUID and etc...

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

Re: Null Pointer exception while startup on homescreen.

[ Edited ]

An uncaught exception will give you a stack trace.  click on it to display the detail. 

 

And please answer all my questions.

Super Contributor
bh1r1th
Posts: 273
Registered: ‎11-23-2010
My Device: 9800 torch

Re: Null Pointer exception while startup on homescreen.

Thank you for the replay peter.

 

Problem solved the problem in my code deactive method.