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

Thank you for visiting the BlackBerry Support Community Forums.

BlackBerry will be closing the BlackBerry Support Community Forums Device Forums on April 1st (Developers, see below)

BlackBerry remains committed to providing excellent customer support to our customers. We are delighted to direct you to the CrackBerry Forums, a well-established and thorough support channel, for continued BlackBerry support. Please visit http://forums.crackberry.com or http://crackberry.com/ask. You can also continue to visit BlackBerry Support or the BlackBerry Knowledge Base for official support options available for your BlackBerry Smartphone.

"When we launched CrackBerry.com 10 years ago, we set out to make it a fun and useful destination where BlackBerry Smartphone owners could share their excitement and learn to unleash the full potential of their BlackBerry. A decade later, the CrackBerry community is as active and passionate as ever and I know our knowledgeable members and volunteers will be excited to welcome and assist more BlackBerry owners with their questions."

- Kevin Michaluk, Founder, CrackBerry.com

Developers, for more information about the BlackBerry Developer Community please review Join the Conversation on the BlackBerry Developer Community Forums found on Inside BlackBerry.

New Developer
Posts: 11
Registered: ‎12-01-2009
My Device: Not Specified

MainScreen.onDisplay() NullPointerException

I make a custom field by extending Field and want to make it clickable. So, I create that field with Field.FOCUSABLE. The app throws a NullPointerException (I think on a null defaultFocus item) in the onDisplay method of my MainScreen (called as a direct result of UiApplication.pushScreen()).


JDE version:

Simulator: Strom 9550


class TabbarIcon extends Field {
    private String _label;
    private int _foregroundColor = Graphics.FULL_WHITE;
    private int _backgroundColor = Graphics.FULL_BLACK;
    private int _width;
    private int _height = 52;
    private String _image;
    private int _padding = 5;
    private int _fontSize = 12;
    TabbarIcon() {   
    public TabbarIcon(String label, String image, int width) {
        _label = label;
        _width = width;
        _image = image;
    protected void paint(Graphics graphics) {
        Bitmap image = Bitmap.getBitmapResource(_image);
        image = Bitmap.getBitmapResource(_image);
        int xOffset = (_width - image.getWidth()) / 2;
        graphics.drawBitmap(xOffset, _padding, _width, _height, image, 0, 0);

        Font currentFont = graphics.getFont();
        graphics.setFont(currentFont.derive(currentFont.getStyle(), _fontSize));
        graphics.drawText(_label, 0, 35, Graphics.HCENTER, _width);
    protected void layout(int width, int height) {
        setExtent(_width, _height);
    public int getPreferredWidth() { 
        return _width; 

    public int getPreferredHeight() { 
         return _height; 
    public boolean isFocusable() {
        return true;
    public boolean navigationClick(int status, int time) {
        return true;

    protected void onFocus(int direction) {

    protected void onUnfocus() {

    protected void drawFocus(Graphics graphics, boolean on) {

New Developer
Posts: 11
Registered: ‎12-01-2009
My Device: Not Specified

Re: MainScreen.onDisplay() NullPointerException

The issue is similar to http://supportforums.blackberry.com/t5/Java-Development/MainScreen-onDisplay-NullPointerException/m-.... I follow that solution but it doesn't solve the issue.

Posts: 1,474
Registered: ‎04-14-2009
My Device: Not Specified

Re: MainScreen.onDisplay() NullPointerException

Please post the full stack trace.

New Developer
Posts: 11
Registered: ‎12-01-2009
My Device: Not Specified

Re: MainScreen.onDisplay() NullPointerException

Screen.onDisplay() <-- boom
Screen.callOnUiEngineAttached( boolean )
UiEngineImpl.addScreen( Screen )
UiEngineImpl$UiEngineOldInterfaceAdapter.pushScreen( Screen )
UiApplication.pushScreen( Screen )
FusionCrmApp.FusionCrmApp() <-- This is my Ui Appcalition
FusionCrmApp.main( String[] )
BlackBerry Development Advisor
Posts: 15,884
Registered: ‎07-09-2008
My Device: BlackBerry PRIV
My Carrier: Bell

Re: MainScreen.onDisplay() NullPointerException

I tried to reproduce this using your code above and was not able to.


Have you customized your onDisplay method?  Check that the bitmap you are referencing is valid and not null.

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
New Developer
Posts: 11
Registered: ‎12-01-2009
My Device: Not Specified

Re: MainScreen.onDisplay() NullPointerException

The error occurs when the main screen also contains BrowserField.

Posts: 1,474
Registered: ‎04-14-2009
My Device: Not Specified

Re: MainScreen.onDisplay() NullPointerException

I'm a bit suspicious of what the stack trace is showing. Looks like you are trying to push a screen before you've created an event thread (this is OK). However, the onDisplay method in the stack trace should not have been called until the event thread is up and running.

New Developer
Posts: 11
Registered: ‎12-01-2009
My Device: Not Specified

Re: MainScreen.onDisplay() NullPointerException

The next reply is the code of mainscreen that call the above custom field.

New Developer
Posts: 11
Registered: ‎12-01-2009
My Device: Not Specified

Re: MainScreen.onDisplay() NullPointerException

import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.FieldChangeListener;
import net.rim.device.api.ui.container.FullScreen;
import net.rim.device.api.ui.container.GridFieldManager;
import net.rim.device.api.ui.container.VerticalFieldManager;
import net.rim.device.api.ui.container.HorizontalFieldManager;
import net.rim.device.api.browser.field2.BrowserField;
import net.rim.device.api.browser.field2.BrowserFieldConfig;
import net.rim.device.api.browser.field2.BrowserFieldListener;
import java.util.Hashtable;
import net.rim.device.api.io.http.HttpHeaders;
import net.rim.device.api.ui.Manager;
import net.rim.device.api.system.Display;
import oracle.apps.sales.mobile.blackberry.options.ApplicationSettings;
import oracle.apps.sales.mobile.blackberry.options.OptionsData;

class FusionCrmMainScreen extends FullScreen implements FieldChangeListener {
    String homeURL = "http://www.google.com";
    String leadsURL = "http://www.gmail.com";
    String oppsURL = "http://www.yahoo.com";
    String contactURL = "http://www.hotmail.com";
    String moreURL = "http://www.ymail.com";

    String imgPath = "img/";

    VerticalFieldManager vManager;
    BrowserField mainBrowser;

    TabbarIcon homeIcon;
    TabbarIcon leadsIcon;
    TabbarIcon oppsIcon;
    TabbarIcon contactIcon;
    TabbarIcon moreIcon;
    FusionCrmMainScreen(long style) {   

        int iconSize = Display.getWidth()/5;
        mainBrowser = new BrowserField();
        vManager = new VerticalFieldManager(Manager.VERTICAL_SCROLL | Field.FIELD_HCENTER | Field.FIELD_TOP | Field.USE_ALL_HEIGHT | Field.USE_ALL_WIDTH);
        HorizontalFieldManager linkManager = new HorizontalFieldManager(Field.FIELD_HCENTER | Field.USE_ALL_HEIGHT | Field.USE_ALL_WIDTH);
        homeIcon = new TabbarIcon("Home", "img/bb_today_trans.png", iconSize);
        leadsIcon = new TabbarIcon("Leads", "img/bb_leads_trans.png", iconSize);
        oppsIcon = new TabbarIcon("Opportunity", "img/bb_opportunities_trans.png", iconSize);
        contactIcon = new TabbarIcon("Contacts", "img/bb_contacts_trans.png", iconSize);
        moreIcon = new TabbarIcon("More", "img/bb_settings_trans.png", iconSize);


        GridFieldManager manager = new GridFieldManager(2,1,Field.FIELD_HCENTER | Field.FIELD_TOP | Field.USE_ALL_HEIGHT | Field.USE_ALL_WIDTH);
        manager.setRowProperty(0, GridFieldManager.AUTO_SIZE, 0);
    public void fieldChanged(Field field, int context)
        if (field == homeIcon) {
        } else if (field == leadsIcon) {
        } else if (field == oppsIcon) {
        } else if (field == contactIcon) {
        } else if (field == moreIcon) {

New Member
Posts: 1
Registered: ‎12-15-2011
My Device: Torch 9860
My Carrier: Claro Ar

Re: MainScreen.onDisplay() NullPointerException

I have the same problem, can anybody help me solve this issue?