开发者

Blackberry application terminated

I am getting error

Application is not responding; process terminated

when I am using a listfield.Dats is coming from server. Here is the code:

listnew = new ListField() {

        /*
         * protected void drawFocus(Graphics graphics, boolean on) { }
         */



        protected boolean trackwheelClick(int status, int time) {

            listFieldIndex = listnew.getSelectedIndex();
            listnew.setFocus();
            System.out.println(listFieldIndex);
            if (listFieldIndex < 0) {
                listFieldIndex = 0;

            }
            try {
                UiApplication.getUiApplication().invokeLater(
                        new Runnable() {
                            public void run() {
                                /*ODProgDetailScreen.shows.removeAllElements();
                                System.out.println("Value is-----"
                                        + listFieldIndex);
                                // System.out.println("ID IS EQUAL TO:-"+
                                // progurl);
                                ODProgDetailScreen.progDetailURL = ((Program) programList2
                                        .elementAt(listFieldIndex)).getId();
                                ODProgDetailScreen.progTitle = ((Program) programList2
                                        .elementAt(listFieldIndex))
                                        .getTitle();
                                // ProgramDetails.shows.removeAllElements();
                                UiApplication.getUiApplication()
                                        .pushScreen(new ODProgDetailScreen());
                                UiApplication.getUiApplication().popScreen(
                                        getScreen());*/
                            }
                        });
            } catch (Exception e) {
            }
            return true;
        }

    };

    listnew.setRowHeight(40);

    // setEmptyString("Hooray, no tasks here!", DrawStyle.HCENTER);

    listnew.setCallback(this);

    rows = new Vector();

    for (int x = 0; x < mDCtaegory.size(); x++) {
        Hashtable hs = (Hashtable)mDCtaegory.elementAt(x);
        row = new TableRowManager();

        // SET THE PRIORITY BITMAP FIELD
        // if high priority, display p1 bitmap

        /*artistImgField = new URLBitmapField(Bitmap
                .getBitmapResource("res/images/bg.jpg"));*/
        HTTPManager engine = new HTTPManager();
          BitmapField bitmap= new BitmapField(engine.readImageFromURL((String) hs.get("img"), 40, 40));
          row.add(bitmap);

BitmapField bitmap1=new BitmapField(engine.readImageFromURL((String) hs.get("ratingimage"), 40, 40));
BitmapField bitmap2=new BitmapField(Bitmap.getBitmapResource("arrow.png"));
        //row.add(bitmap1);


        LabelField task = new LabelField(hs.get("title"), LabelField.USE_ALL_WIDTH);



        row.add(task);
        row.add(bitmap1);
        row.add(bitmap2);

        rows.addElement(row);
    }
    listnew.setSize(rows.size());
    gridbackManager=new VerticalFieldManager(VerticalFieldManager.NO_HORIZONTAL_SCROLL|VerticalFieldManager.VERTICAL_SCROLL){
          protected void paintBackground(Graphics graphics)
          {  

                    int c = graphics.getColor();
                    //graphics.setColor(Color.WHITESMOKE);
                    graphics.drawBitmap(0, 0, backbitmap.getWidth(), backbitmap.getHeight(),backbitmap,0,0);

                    //graphics.setColor(c);

            super.paintBackground(graphics);
          }
          protected void sublayout( int maxWidth, int maxHeight )
          {
              int width = backbitmap.getWidth();
              int height = backbitmap.getHeight();
              super.sublayout( width, height);
              layoutChild(_vfm,width, height);
              setPositionChild(_vfm,0, 0);
              setExtent( width, height);
          }
        };
        mainlayout=new VerticalFieldManager(VerticalFieldManager.NO_HORIZONTAL_SCROLL|VerticalFieldManager.VERTICAL_SCROLL){
              protected void paintBackground(Graphics graphics)
              {  

                        int c = graphics.getColor();
                        //graphics.setColor(Color.WHITESMOKE);
                        graphics.drawBitmap(0, 0, backbitmap.getWidth(), backbitmap.getHeight(),backbitmap,0,0);

                        //graphics.setColor(c);

                super.paintBackground(graphics);

              }
              protected void sublayout( int maxWidth, int maxHeight )
              {
                  int width = backbitmap.getWidth();
                  int height = backbitmap.getHeight();
                  super.sublayout( width, height);
                  layoutChild(backbittopfield,maxWidth, maxHeight);
                  setPositionChild(backbittopfield,15, 20);
                  layoutChild(gridbackManager,maxWidth, maxHeight);
                  setPositionChild(gridbackManager,15, 43);
                  layoutChild(backbitbottomfield,maxWidth, maxHeight);
         开发者_Python百科         setPositionChild(backbitbottomfield,15, 194);
                  setExtent(Display.getWidth(), Display.getHeight());
              }
            };
    _vfm = new VerticalFieldManager(Manager.VERTICAL_SCROLL
            | Field.USE_ALL_HEIGHT | Field.USE_ALL_WIDTH) {

        public void paint(Graphics g) {
            int[] X_PTS_MAIN = { 0, Display.getWidth(), Display.getWidth(),
                    0 };
            int[] Y_PTS_MAIN = { 0, 0, Display.getHeight(),
                    Display.getHeight() };
            int[] drawColors_MAIN = { Color.WHITESMOKE, Color.WHITESMOKE,
                    Color.WHITESMOKE, Color.WHITESMOKE };

            try {
                // Draw the gradients
                g.drawShadedFilledPath(X_PTS_MAIN, Y_PTS_MAIN, null,
                        drawColors_MAIN, null);

            } catch (IllegalArgumentException iae) {
                System.out.println("Bad arguments.");
            }

            g.setBackgroundColor(Color.WHITESMOKE);
            g.clear();
            // Call super to paint the graphics on the inherited window
            super.paint(g);

        }

        protected boolean navigationMovement(int dx, int dy, int status,
                int time) {
            this.invalidate();
            return super.navigationMovement(dx, dy, status, time);
        }

        protected void sublayout(int maxWidth, int maxHeight) {

            layoutChild(listnew, maxWidth, maxHeight);
            setPositionChild(listnew, 0, 0);

            setExtent( 292, 150);
        }

    };
    _vfm.add(listnew);
    mainlayout.setBackground(bg);
    mainlayout.add(backbittopfield);
    gridbackManager.add(_vfm);
    mainlayout.add(gridbackManager);
    mainlayout.add(backbitbottomfield);
    add(headerbitmapfield);
    add(mainlayout);
    // this.add(listnew);
    UiApplication.getUiApplication().invokeLater(new Runnable() {
        public void run() {
            listnew.invalidate();
        }
    }, 500, true);

Is it due to the list.invalidate() that I am using at the bottom?


The ANR is because you are trying to make an HTTP connection on the UI thread. This is a big no-no! You need to initialize the ListField as empty and start a separate, background thread to read the data. When the data has all arrived, call invokeLater with a Runnable that will populate the list.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜