2011-02-01 18 views
0
public class CategoriesUI extends MainScreen implements ListFieldCallback { 

    //categoryimport.listingnodup is the current categories with no duplicates 
    public Categories categoryimport = new Categories(); //brings in all infromation from Categories.java 

    private ListField allcategories; 

    CategoriesUI() {  

     this.add(new LabelField("List of Categories")); 
     allcategories = new ListField(categoryimport.listingnodup.size()); 
     allcategories.setCallback(this); //we manage the interaction! 
     this.add(allcategories); 

    } 

    protected boolean onSavePrompt() { 

     return true; 
    } 


    //Implemented Call Back Methods follow 

    //draw the current row 
    public void drawListRow(ListField list, Graphics g, int index, int y, int w) { 

     catdrawer categorydraw = (catdrawer) this.get(list, index); 
     int drawColor = Color.BLACK; 
     g.setColor(drawColor); 
     g.drawText(categorydraw.cat, 0, y, 0, w); 

    } 

    public int getPreferredWidth(ListField list) { 

     return Display.getWidth(); 

    } 

    public int indexOfList(ListField listField, String prefix, int start) { 

     //Not a current implementation this is really just commented out 
     return start; 

    } 

    //Returns the object at the specified index 
    public Object get(ListField list, int index){ 

     return categoryimport.listingnodup.elementAt(index); 

    } 

    class catdrawer { 

     public String cat = categoryimport.listingnodup.toString(); 

    }  
    } 

該程序符合正確,但是當它在Simulator 8800中運行時,會在執行此代碼時崩潰。繪製一個ListField並根據來自XML文件的矢量解析信息繪製屏幕畫面

+1

它如何崩潰?它會產生堆棧跟蹤嗎?您可能想要包括...什麼是模擬器8800? – 2011-02-01 00:22:32

+0

模擬器8800意味着黑莓模擬器模擬黑莓8800. – 2011-02-01 01:26:54

回答

1

該代碼是問題的根源:

catdrawer categorydraw = (catdrawer) this.get(list, index); 

當categorydraw爲空,則調用DrawText的3行以後將拋出異常。你需要檢查null。