BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 08-01-2007, 06:44 AM   #1 (permalink)
Thumbs Must Hurt
 
Join Date: Jan 2007
Location: India
Model: 8700g
Carrier: Airtel
Posts: 117
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default NullpointerException

Please Login to Remove!

I dont know where i am going wrong.
Code:
package com.rim.samples.device.LostnFound;

import net.rim.device.api.ui.FieldChangeListener;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.component.BitmapField;
import net.rim.device.api.ui.MenuItem;
import net.rim.device.api.ui.component.Menu;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.system.Bitmap;

class Lost_n_Found_Entry extends MainScreen {    
    private static Bitmap   _bitmap ;
    UiApplication           _UiApp;
    MenuItem                _MeniItem;
    String                  _S_enable;
    public Lost_n_Found_Entry() {    
        _bitmap  = Bitmap.getBitmapResource("ob_splash.PNG");
        add(new BitmapField(_bitmap, Field.FIELD_HCENTER | Field.FIELD_VCENTER));
        _UiApp   = UiApplication.getUiApplication();        
        if(Lost_n_Found_Passwd._s_Enable_Flag == 0)
            _S_enable = "Enable";
        else
            _S_enable = "Disable";
    }   
    
    MenuItem _Enable = new MenuItem(_S_enable, 200000, 10) {
        public void run() {
            if(_S_enable.equals("Enable") ) {
                Lost_n_Found_Passwd._s_Enable_Flag = 1;
                _UiApp.popScreen(_UiApp.getActiveScreen());
                _UiApp.pushScreen(new Lost_n_Found_Entry());
            } else {
                Lost_n_Found_Passwd._s_Enable_Flag = 0;
                _UiApp.popScreen(_UiApp.getActiveScreen());
                _UiApp.pushScreen(new Lost_n_Found_Entry());
            }
        }
    };
    MenuItem _Settings = new MenuItem("Settings", 200000, 10) {
        public void run() {
            _UiApp.popScreen(_UiApp.getActiveScreen());
            _UiApp.pushScreen(new Lost_n_Found_Settings());
        }
    };
    MenuItem _About = new MenuItem("About", 200000, 10) {
        public void run() {            
        }
    };
    MenuItem _Exit = new MenuItem("Exit", 200000, 10) {
        public void run() {
            System.exit(0);
        }
    }; 
    
    protected void makeMenu(Menu menu, int instance) {  
        menu.add(_Enable);
        menu.add(_Settings);
        menu.addSeparator();
        menu.add(_About);
        menu.addSeparator();
        menu.add(_Exit);    
        super.makeMenu(menu, instance);    
    }
}
When ever i click on the trackwheel to view the menu , i get a nullPointerException.
__________________
Thanks
Meenal
Offline  
Old 08-01-2007, 07:48 AM   #2 (permalink)
Thumbs Must Hurt
 
Join Date: Jun 2007
Location: Bangladesh
Model: 8800
PIN: N/A
Carrier: EDGE
Posts: 93
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Meenal,

Before overriding "protected void makeMenu(Menu menu, int instance)" function, you have to initialized all items or variables that you want to use here.

In your code you are going to add "MenuItem _Enable = new MenuItem(_S_enable, 200000, 10)" MenuItem, without initializing xxx8220;_S_enablexxx8221; variable. You have to initialize first to access this variable. You may declare this variable as the following or as your experience:

Code:
String _S_enable = "Enable";
Hope this will work!

Cheers!
ARIF
Offline  
Closed Thread


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





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