黑莓应用终止

时间:2011-08-26 15:12:40

标签: blackberry

我收到错误

  

应用程序没有响应;流程已终止

当我使用listfield.Dats来自服务器时。这是代码:

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);
                  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);

是否归因于我在底部使用的list.invalidate()

1 个答案:

答案 0 :(得分:1)

ANR是因为您尝试在UI线程上建立HTTP连接。这是big no-no!您需要将ListField初始化为空并启动一个单独的后台线程来读取数据。数据全部到达后,使用将填充列表的Runnable调用invokeLater