2011-08-26 105 views
0

我收到錯誤黑莓應用程序終止

應用程序沒有響應;進程終止

當我使用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); 

它是由於​​,我現在用的底部?

+0

我會嘗試設置一個斷點調試,直到應用程序代碼停止執行。另外,當我創建一個無限循環時,我已經發生過這種情況,所以請注意這一點。 – jprofitt

回答

1

的ANR是因爲你正試圖使UI線程上的HTTP連接。這是一個big no-no!您需要將ListField初始化爲空,並啓動一個單獨的後臺線程來讀取數據。當數據已全部抵達,請致電invokeLater有一個Runnable,將填充列表。

+0

thnk U,可提供任何示例代碼 – arunabha

+0

但我做同樣的事情在我之前列表現場畫面,我可以,同樣的邏輯我使用上真 – arunabha

+0

如果請求發生足夠快,它只是看起來容易fethc數據,沒有錯誤就像在應用程序中暫時掛起一樣。如果時間太長,系統會認爲該應用程序已被凍結並終止。 – jprofitt