a strange problem on quite demand. Pls help me. Thank you very much

public class Searchbox extends Manager {
    private Bitmap searchbarBitmap;
    private int searchbarheight;
    private int searchbarwidth;
    public Searchbox() {
        super(NO_VERTICAL_SCROLL);
        if(Display.getHeight()<440){
            searchbarheight = getFont().getHeight() + 13;
            searchbarwidth=Display.getWidth()-60;
            searchbarBitmap = Scaleimage.resizeBitmap("Bold/fake_search_bar.png",
                    searchbarwidth, searchbarheight);
        }else{
        searchbarheight = getFont().getHeight()+10;
        searchbarwidth=Display.getWidth();
        searchbarBitmap = Scaleimage.resizeBitmap("Storm/fake_search_bar.png",
                searchbarwidth, searchbarheight);
        }
    }

    protected void sublayout(int width, int height) {
        Field field = getField(0);
        layoutChild(field, searchbarBitmap.getWidth(), searchbarBitmap
                .getHeight());
        if(Display.getHeight()<440){
        setPositionChild(field, 30, 6);}
        else{
            setPositionChild(field, 45, 6);
        }
        setExtent(searchbarBitmap.getWidth(), searchbarBitmap.getHeight());
    }
    public int getPreferredWidth()
    {
        return searchbarBitmap.getWidth();
    }
    public int getPreferredHeight()
    {
        return searchbarBitmap.getHeight();
    }
    protected void paint(Graphics graphics) {
        graphics.drawBitmap(0, 0, searchbarBitmap.getWidth(), searchbarBitmap
                .getHeight(), searchbarBitmap, 0, 0);
        super.paint(graphics);
    }

    public String getText() {
        return ((EditField) getField(0)).getText();
    }

}

I'm writing a screen, this screen is the first screen of this application. This screen have a lot of buttons and a search box. The problem is:

When I click on the button esc to quite this request if the searchbox onfocus, it will get the Eception message: NullpointException

public class StorelistScreen extends MainScreen implements Container {
    private Merchant merchant;
    private VerticalFieldManager backgroundmanager;
    private LabelField title;
    private ListField storelist;
    private storelistCallback storelistCallback;
    private VerticalFieldManager listmanager;
    private String titleString;
    private Vector storeVector;
    private String imageurl;
    private String cat;
    private Mapbar mapbar;
    private double curlat;
    private double curlng;
    private Vector imageVector;
    private boolean offer;
    private BitmapField offerlogoField;
    private Bitmap offerBitmap;
    private HorizontalFieldManager titleManager;
    private Vector offerVector;
    private HorizontalFieldManager bottombuttonManager;
    private VerticalFieldManager bottomManager;

    public StorelistScreen(Merchant merchant, String tilesString,
            Vector storeVector, String cat, Vector imageVector,
            final boolean offer, double curlat, double curlng,
            Vector offerVector) {
        super(NO_VERTICAL_SCROLL | NO_VERTICAL_SCROLLBAR|DEFAULT_CLOSE);
        this.merchant = merchant;
        this.titleString = tilesString;
        this.storeVector = storeVector;
        this.cat = cat;
        this.imageVector = imageVector;
        this.offer = offer;
        this.offerVector = offerVector;
        setCurlat(curlat);
        setCurlng(curlng);
        VirtualKeyboard vk = null;
        if ((vk = UiApplication.getUiApplication().getActiveScreen()
                .getVirtualKeyboard()) != null) {
            vk.setVisibility(VirtualKeyboard.HIDE);
        }
        if (Display.getWidth() < 440&&Display.getHeight()>440) {
            imageurl = "Storm/amex-splash.png";
        } else {
            imageurl = "Bold/detail_background_without_webview.png";
        }
        int backgroundwidth=Display.getWidth();
        int backgroundheight=Display.getHeight();
        final Bitmap backgroundbitmap = Scaleimage.resizeBitmap(imageurl,
                backgroundwidth,backgroundheight);
        backgroundmanager = new VerticalFieldManager(NO_VERTICAL_SCROLL
                | NO_VERTICAL_SCROLLBAR | USE_ALL_HEIGHT | USE_ALL_WIDTH
                | NO_SYSTEM_MENU_ITEMS) {
            protected void sublayout(int width, int height) {
                super.sublayout(Display.getWidth(), Display.getHeight());
                Field field = (Field) getField(0);
                Manager field2 = (Manager) getField(1);
                layoutChild(field, Display.getWidth(), field.getHeight());
                if (Display.getHeight() < 480) {
                    setPositionChild(field, 0, 10);
                    setPositionChild(field2, 5, 70);
                    layoutChild(field2, Display.getWidth() - 10, Display
                            .getHeight()
                            - 70 - mapbar.getPreferredHeight());
                } else {
                    setPositionChild(field, 0, 10);
                    setPositionChild(field2, 5, 60);
                    layoutChild(field2, Display.getWidth() - 10, Display
                            .getHeight()
                            - 60 - mapbar.getHeight() - 30);
                }
                setExtent(Display.getWidth(), Display.getHeight());
            }

            protected void paint(Graphics graphics) {
                graphics.clear();
                graphics.drawBitmap(0, 0, Display.getWidth(), Display
                        .getHeight(), backgroundbitmap, 0, 0);
                super.paint(graphics);
            }
        };
        if (offer) {
            if (titleString.equalsIgnoreCase("1")) {
                offerBitmap = Bitmap
                        .getBitmapResource("Bold/list_logo_selects.png");
            } else if (titleString.equalsIgnoreCase("2")) {
                offerBitmap = Bitmap
                        .getBitmapResource("Bold/list_logo_10X.png");
            } else {
                offerBitmap = Bitmap.getBitmapResource("Bold/list_logo_15.png");
            }
            offerlogoField = new BitmapField(offerBitmap, FIELD_HCENTER
                    | USE_ALL_WIDTH);
        } else {
            title = new LabelField() {
                public void layout(int width, int height) {
                    setExtent(Display.getWidth(), 30);
                }

                public void paint(Graphics g) {
                    g.setColor(5934280);
                    g.drawText(titleString, 0, 0, DrawStyle.HCENTER, Display
                            .getWidth());
                    super.paint(g);
                }
            };
        }
        titleManager = new HorizontalFieldManager(NO_HORIZONTAL_SCROLL
                | NO_HORIZONTAL_SCROLLBAR) {
            protected void sublayout(int width, int height) {
                super.sublayout(width, height);
                if (getField(0) == title) {
                    if (Display.getHeight() < 440) {
                        setPositionChild(getField(0), 0, 10);
                    } else {
                        setPositionChild(getField(0), 0, 20);
                    }
                } else {
                    if (Display.getHeight() < 440) {
                        setPositionChild(getField(0), 150, 0);
                    } else {
                        setPositionChild(getField(0), 100, 0);
                    }
                }
                setExtent(Display.getWidth(), height);
            }
        };
        if (offer) {
            titleManager.add(offerlogoField);
        } else {
            titleManager.add(title);
        }
        backgroundmanager.add(titleManager);
        listmanager = new VerticalFieldManager(VERTICAL_SCROLL
                | VERTICAL_SCROLLBAR);
        backgroundmanager.add(listmanager);
        final Bitmap mapbuttonbitmap = Bitmap
                .getBitmapResource("Storm/map_button.png");
        storeDTO sDto = (storeDTO) storeVector.elementAt(0);
        double storelat = sDto.getLat();
        double storelng = sDto.getLng();
        String firstdbname = sDto.getDbaname();
        String firstadd1 = sDto.getAdd1();
        mapbar = new Mapbar(mapbuttonbitmap, storelat, storelng, firstdbname,
                firstadd1);
        if (Display.getWidth()<440&& Display.getHeight()>440) {
        bottombuttonManager = new HorizontalFieldManager(NO_HORIZONTAL_SCROLL
                | NO_HORIZONTAL_SCROLLBAR);
        int offersize = offerVector.size();
        int buttonwidth = Display.getWidth() / (offersize + 2);
        StatusButton home = new StatusButton("Home", true, Field.FIELD_HCENTER,
                buttonwidth, 30, merchant);
        StatusButton cards = new StatusButton("Cards", false,
                Field.FIELD_HCENTER, buttonwidth, 30, merchant);
        bottombuttonManager.add(home);
        for (int i = 0; i < offersize; i++) {
            offerDto offerdto = (offerDto) offerVector.elementAt(i);
            final String offernum = offerdto.getOffer();
            String offertitle = offerdto.getTitle();
         String offersString =null;
            if (cat.equalsIgnoreCase("0")) {
                offersString = "http://amex.isingeo.com/search?lat=lat="
                        + Double.toString(getCurlat())
                        + "&lng="
                        + Double.toString(getCurlng())
                        + "&udid=wibble&nearby=1&offer=" + offernum;
            } else {
                offersString = "http://amex.isingeo.com/search?lat="
                        + Double.toString(getCurlat()) + "&lng="
                        + Double.toString(getCurlng())
                        + "&udid=wibble&nearby=1&cat=" + cat
                        + "&offer=" + offernum;
            }
            StatusButton statusButton = new StatusButton(offertitle, offernum,
                    Field.FIELD_HCENTER, offersString, merchant, buttonwidth,
                    30, this);
            bottombuttonManager.add(statusButton);

        }
        bottombuttonManager.add(cards);
        bottomManager = new VerticalFieldManager(NO_VERTICAL_SCROLL
                | NO_VERTICAL_SCROLLBAR | FIELD_HCENTER);
            bottomManager.add(mapbar);
            bottomManager.add(bottombuttonManager);
            setStatus(bottomManager);
        } else {
            setStatus(mapbar);
        }
        add(backgroundmanager);
        setstoreinfo();
    }

    protected boolean onSavePrompt() {
        return false;
    }

    public void setstoreinfo() {
        int storelistlength = storeVector.size();
        storelist = new ListField() {
            private boolean hasFocus = false;

            public void onFocus(int direction) {
                hasFocus = true;
            }

            public void onUnfocus() {
                hasFocus = false;
                super.onUnfocus();
                invalidate();
            }

            public void paint(Graphics graphics) {
                int width = Display.getWidth();
                XYRect redrawRect = graphics.getClippingRect();
                if (redrawRect.y < 0) {
                    throw new IllegalStateException("Error with clipping rect.");
                }
                int rowHeight = getRowHeight();

                int curSelected;

                if (hasFocus) {
                    curSelected = getSelectedIndex();

                } else {
                    curSelected = -1;
                }

                int startLine = redrawRect.y / rowHeight;
                int endLine = (redrawRect.y + redrawRect.height - 1)
                        / rowHeight;
                endLine = Math.min(endLine, getSize() - 1);
                int y = startLine * rowHeight;
                int[] yInds = new int[] { y, y, y + rowHeight, y + rowHeight };
                int[] xInds = new int[] { 0, width, width, 0 };

                ListFieldCallback callBack = this.getCallback();

                for (; startLine <= endLine; ++startLine) {
                    storeDTO dtostore = (storeDTO) callBack
                            .get(this, startLine);
                    if (startLine == curSelected) {

                        graphics.setColor(11584734);
                        graphics.drawFilledPath(xInds, yInds, null, null);
                        if(Display.getWidth()<440&&Display.getHeight()>440){
                            drawforStorm(graphics, dtostore, y, width);
                        }
                        else{
                        drawforBold(graphics, dtostore, y, width);}

                    } else {
                        if(Display.getWidth()<440&&Display.getHeight()>440){
                            drawforStorm(graphics, dtostore, y, width);
                        }
                        else{
                        drawforBold(graphics, dtostore, y, width);}
                    }
                    y += rowHeight;
                    yInds[0] = y;
                    yInds[1] = yInds[0];
                    yInds[2] = y + rowHeight;
                    yInds[3] = yInds[2];
                }

                // super.paint(graphics);
            }

            private void drawforBold(Graphics graphics, storeDTO dtostore,
                    int startLine, int width) {
                Bitmap imageBitmap = dtostore.getImagebitmap();
                int imagewidth = imageBitmap.getWidth() + 10;
                String cuisine = dtostore.getCuisine();
                String dbname = dtostore.getDbaname();
                String add1 = dtostore.getAdd1();
                String add2 = dtostore.getAdd2();
                String distance = dtostore.getDistance();
                double distancedouble = Double.parseDouble(distance);
                distancedouble = Math.floor(distancedouble * 10) / 10;
                String finaldistance = String.valueOf(distancedouble) + "km";
                String state = dtostore.getState();
                graphics.drawBitmap(10, startLine, width, imageBitmap
                        .getHeight(), imageBitmap, 0, 0);
                FontFamily family = null;
                try {
                    family = FontFamily.forName(FontFamily.FAMILY_SYSTEM);
                } catch (ClassNotFoundException e) {
                    e.printStackTrace();
                }
                Font font = family.getFont(Font.APPLICATION, 15);
                graphics.setFont(font);
                graphics.setColor(5929160);
                graphics.drawText(dbname, imagewidth, startLine,
                        DrawStyle.LEFT, width);
                Font font2 = family.getFont(Font.APPLICATION, 12);
                graphics.setColor(5925199);
                graphics.setFont(font2);
                graphics.drawText(cuisine, imagewidth, startLine
                        + font.getHeight(), DrawStyle.LEFT, width);
                graphics.setColor(6908265);
                graphics.drawText(add1, imagewidth, startLine
                        + font.getHeight() + font2.getHeight(), DrawStyle.LEFT,
                        width);
                graphics.drawText(add2 + " " + state, imagewidth, startLine
                        + font.getHeight() + font2.getHeight() * 2,
                        DrawStyle.LEFT, width);
                graphics.setColor(5929160);
                graphics.drawText(finaldistance, Display.getWidth() - 80,
                        startLine, DrawStyle.LEFT, Display.getWidth() - 40);
                graphics.drawLine(5, startLine, Display.getWidth() - 10,
                        startLine);
            }
            private void drawforStorm(Graphics graphics, storeDTO dtostore,
                    int startLine, int width) {
                Bitmap imageBitmap = dtostore.getImagebitmap();
                int imagewidth = imageBitmap.getWidth() + 10;
                String cuisine = dtostore.getCuisine();
                String dbname = dtostore.getDbaname();
                String add1 = dtostore.getAdd1();
                String add2 = dtostore.getAdd2();
                String distance = dtostore.getDistance();
                double distancedouble = Double.parseDouble(distance);
                distancedouble = Math.floor(distancedouble * 10) / 10;
                String finaldistance = String.valueOf(distancedouble) + "km";
                String state = dtostore.getState();
                graphics.drawBitmap(10, startLine, width, imageBitmap
                        .getHeight(), imageBitmap, 0, 0);
                FontFamily family = null;
                try {
                    family = FontFamily.forName(FontFamily.FAMILY_SYSTEM);
                } catch (ClassNotFoundException e) {
                    e.printStackTrace();
                }
                Font font = family.getFont(Font.APPLICATION, 13);
                graphics.setFont(font);
                graphics.setColor(5929160);
                graphics.drawText(dbname, imagewidth, startLine,
                        DrawStyle.LEFT, width);
                Font font2 = family.getFont(Font.APPLICATION, 12);
                graphics.setColor(5925199);
                graphics.setFont(font2);
                graphics.drawText(cuisine, imagewidth, startLine
                        + font.getHeight(), DrawStyle.LEFT, width);
                graphics.setColor(6908265);
                graphics.drawText(add1, imagewidth, startLine
                        + font.getHeight() + font2.getHeight(), DrawStyle.LEFT,
                        width);
                graphics.drawText(add2 + " " + state, imagewidth, startLine
                        + font.getHeight() + font2.getHeight() * 2,
                        DrawStyle.LEFT, width);
                graphics.setColor(5929160);
                graphics.drawText(finaldistance, Display.getWidth() - 80,
                        startLine, DrawStyle.LEFT, Display.getWidth() - 10);
                graphics.drawLine(5, startLine, Display.getWidth() - 10,
                        startLine);
            }

            protected boolean navigationClick(int status, int time) {
                if (getSize() != 0) {
                    if ((status & KeypadListener.STATUS_TRACKWHEEL) != KeypadListener.STATUS_TRACKWHEEL) {
                        storeDTO storedto = (storeDTO) storelistCallback.get(
                                storelist, getSelectedIndex());
                        if (!offer) {
                            merchant.showStoreDetail(storedto, false);
                        } else {
                            merchant.showStoreDetail(storedto, true);
                        }
                    }
                }
                return super.navigationClick(status, time);
            }
        };
        storelistCallback = new storelistCallback();
        storelist.setCallback(storelistCallback);
        storelist.setRowHeight(50);
        for (int i = 0; i < storelistlength; i++) {
            storeDTO store = (storeDTO) storeVector.elementAt(i);
            storelist.insert(i);
            storelistCallback.Insert(store, i);
        }
        listmanager.add(storelist);
    }

    public void formenuitem(String urlstring, String offernum) {
        Bitmap offernewBitmap = null;
        this.offer = true;
        final String title = offernum;
        if (offer) {
            if (title.equalsIgnoreCase("1")) {
                offernewBitmap = Bitmap
                        .getBitmapResource("Bold/list_logo_selects.png");
            } else if (title.equalsIgnoreCase("2")) {
                offernewBitmap = Bitmap
                        .getBitmapResource("Bold/list_logo_10X.png");
            } else {
                offernewBitmap = Bitmap
                        .getBitmapResource("Bold/list_logo_15.png");
            }
        }
        BitmapField offernewBitmapField = new BitmapField(offernewBitmap,
                FIELD_HCENTER);
        titleManager.replace(titleManager.getField(0), offernewBitmapField);
        String jString = GetPostJson.getjsonString(urlstring);
        JSONObject jsonObject = null;
        try {
            jsonObject = new JSONObject(jString);
            int num = jsonObject.getInt("n");
            if (num>0) {
                int blistlength = storelist.getSize();
                for (int n = 0; n < blistlength; n++) {
                    storelist.delete(0);
                    storelistCallback.removeItem(0);
                }
                JSONArray jsonArray = jsonObject.getJSONArray("merchants");
                int jlength = jsonArray.length();
                for (int i = 0; i < jlength; i++) {
                    storeDTO storedto = new storeDTO();
                    JSONObject storeJsonObject = jsonArray.getJSONObject(i);
                    String curcat = Integer.toString(storeJsonObject.getInt("cat1"));
                    Bitmap iconBitmap = null;
                    int imagelength = imageVector.size();
                    for (int n = 0; n < imagelength; n++) {
                        imagedto image = (imagedto) imageVector.elementAt(n);
                        if (curcat.equalsIgnoreCase(image.getCat())) {
                            iconBitmap = image.getIcon();
                        }
                    }
                    if (iconBitmap != null) {
                        storedto.setOfferlink(storeJsonObject
                                .getString("offer_link"));
                        storedto.setAdd1(storeJsonObject.getString("add1"));
                        storedto.setAdd2(storeJsonObject.getString("add2"));
                        storedto.setDbaname(storeJsonObject
                                .getString("dbaname"));
                        storedto.setDistance(storeJsonObject
                                .getString("distance"));
                        storedto.setImagebitmap(iconBitmap);
                        storedto.setLat(storeJsonObject.getDouble("lat"));
                        storedto.setLng(storeJsonObject.getDouble("lng"));
                        storedto.setPhone(storeJsonObject.getString("phone"));
                        storedto.setState(storeJsonObject.getString("state"));
                        if (cat.equalsIgnoreCase("0")) {
                            storedto.setCuisine(storeJsonObject
                                    .getString("description"));
                        } else {
                            storedto.setCuisine(storeJsonObject
                                    .getString("cuisine"));
                        }
                        storelist.insert(i);
                        storelistCallback.Insert(storedto, i);
                    }

                }
            }
            else{
                int blistlength = storelist.getSize();
                for (int n = 0; n < blistlength; n++) {
                    storelist.delete(0);
                    storelistCallback.removeItem(0);
                }
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
        titleManager.invalidate();
        storelist.invalidate();
    }

    private MenuItem cardItem = new MenuItem("Cards", 100, 10) {
        public void run() {
            String cardurl = "http://amex.isingeo.com/cards";
            String jString = GetPostJson.getjsonString(cardurl);
            Vector cardsVector = new Vector();
            try {
                JSONArray jsonArray = new JSONArray(jString);
                int jlength = jsonArray.length();
                for (int i = 0; i < jlength; i++) {
                    JSONObject jsonObject = jsonArray.getJSONObject(i);
                    CardDto cardDto = new CardDto();
                    String imageurl = jsonObject.getString("face_url");
                    Bitmap faceBitmap = Getimage.getbitmapdata(imageurl);
                    if (faceBitmap != null) {
                        cardDto.setFaceBitmap(Scaleimage.resizeBitmap(
                                faceBitmap, 90, 57));
                        cardDto.setCard_title(jsonObject
                                .getString("card_title"));
                        cardDto.setDescription(jsonObject
                                .getString("description"));
                        cardsVector.addElement(cardDto);
                    }
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
            merchant.showCardsScreen(cardsVector);
        }
    };

    protected void makeMenu(Menu menu, int instance) {
         if (!(Display.getHeight() == 480 && Display.getWidth() == 360)) {
        int offersize = offerVector.size();
        for (int i = 0; i < offersize; i++) {
            offerDto oDto = (offerDto) offerVector.elementAt(i);
            final String offertitle = oDto.getTitle();
            final String offernum = oDto.getOffer();
            menu.add(new MenuItem(offertitle, 100, 10) {
                public void run() {
                    String offersString = null;
                    if (cat.equalsIgnoreCase("0")) {
                        offersString = "http://amex.isingeo.com/search?lat=lat="
                                + Double.toString(getCurlat())
                                + "&lng="
                                + Double.toString(getCurlng())
                                + "&udid=wibble&nearby=1&offer=" + offernum;
                    } else {
                        offersString = "http://amex.isingeo.com/search?lat="
                                + Double.toString(getCurlat()) + "&lng="
                                + Double.toString(getCurlng())
                                + "&udid=wibble&nearby=1&cat=" + cat
                                + "&offer=" + offernum;
                    }
                    formenuitem(offersString, offernum);
                }
            });
        }
        menu.add(cardItem);
         }
    }

     protected void sublayout(int width, int height) {
     setPositionDelegate(0, 0);
     layoutDelegate(width, height);
     setPosition(0, 0);
     setExtent(width, height);
     }

    // public boolean onClose(){
    // this.close();
    // return true;
    // }
    public void setCurlat(double curlat) {
        this.curlat = curlat;
    }

    public double getCurlat() {
        return curlat;
    }

    public void setCurlng(double curlng) {
        this.curlng = curlng;
    }

    public double getCurlng() {
        return curlng;
    }
}

If you run this application via a simulator, simply press the debug icon (it's the one that looks like a bug, just left of the "Run" icon), but make sure that you debug the correct application. If you are running on a simulator application, attach the device to your computer via USB and go to--> Debug configurations--> BlackBerry device debugging--> debugging the server (1) (or any other profile you want to use this topic). He will have to use the JDE 'Join all connected', but you can specify the device. Then from there, you can select the debug icon. All output of the Simulator will be displayed in the console at the bottom of the screen window. Also, there is a default debugging view that can be used to display the stack traces, etc. Breakpoints will work only in debug mode.

Hope that helps,

~ Dom

Tags: BlackBerry Developers

Similar Questions

Maybe you are looking for