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
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: 5.0.0.14

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) {
        super(Field.FOCUSABLE);
        _label = label;
        _width = width;
        _image = image;
    }
   
    protected void paint(Graphics graphics) {
        graphics.setBackgroundColor(_backgroundColor);
        graphics.clear();
        graphics.setColor(_foregroundColor);
       
        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) {
        fieldChangeNotify(0);
        return true;
    }

    protected void onFocus(int direction) {
        super.onFocus(direction);
    }

    protected void onUnfocus() {
        super.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.

Developer
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,753
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.
Found a bug? Report it using Issue Tracker
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.

Developer
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) {   
        super(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);
        vManager.add(mainBrowser);
       
        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);

        homeIcon.setChangeListener(this);
        leadsIcon.setChangeListener(this);
        oppsIcon.setChangeListener(this);
        contactIcon.setChangeListener(this);
        moreIcon.setChangeListener(this);

        linkManager.add(homeIcon);
        linkManager.add(leadsIcon);
        linkManager.add(oppsIcon);
        linkManager.add(contactIcon);
        linkManager.add(moreIcon);
       
        GridFieldManager manager = new GridFieldManager(2,1,Field.FIELD_HCENTER | Field.FIELD_TOP | Field.USE_ALL_HEIGHT | Field.USE_ALL_WIDTH);
        manager.setRowPadding(0);
        manager.setColumnPadding(0);
        manager.setCellPadding(0);
        manager.setRowProperty(0, GridFieldManager.AUTO_SIZE, 0);
  
        manager.add(vManager);
        manager.add(linkManager);
        add(manager);
        mainBrowser.requestContent(homeURL);
    }
   
    public void fieldChanged(Field field, int context)
       
        if (field == homeIcon) {
            mainBrowser.requestContent(homeURL);
        } else if (field == leadsIcon) {
            mainBrowser.requestContent(leadsURL);
        } else if (field == oppsIcon) {
            mainBrowser.requestContent(oppsURL);
        } else if (field == contactIcon) {
            mainBrowser.requestContent(contactURL);
        } else if (field == moreIcon) {
            mainBrowser.requestContent(moreURL);
        }
       
    }
   
}

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?