BlackBerry ObjectListField

时间:2010-11-24 13:01:38

标签: list blackberry nullpointerexception

我正在开发JDE 4.6.1下的BlackBerry项目。问题是当向列表添加项时,从方法measureListRow抛出NullPointerException

NPE callstack:

CustomerListField(ObjectListField).measureListRow(ListField, int, int)
CustomerListField(ListField).layout(int, int)
CustomerListField(ObjectListField).layout(int, int) 
VList(Manager).layoutChild(Field, int, int) 

注意:

  • db_.getDataAccess() - 数据库
  • getListCount - 获取列表中的项目数
  • CustomerListItem - 列表项的结构

相关代码:

public class CustomerListField extends ObjectListField implements   ListFieldCallback, ChangeListener {

    private PagedDataFetcher dataFetcher = new CustomerListPagedDataFetcher();

    …

    public CustomerListField() {
        try {
            super.set(new Object[db_.getDataAccess().getListCount()]);
        } catch (Throwable e) {
        }
    }

    public void drawListRow(ListField listField, Graphics g, int index, int y,
                            int width) {
        CustomerListItem currentRow = (CustomerListItem) get(listField, index);
        …
    }

    public Object get(ListField list, int index) {
        try {
           return dataFetcher.getRowAtIndex(index);
        } catch (Throwable e) {
           return null;
        }
    }

// To obtain the data
public class CustomerListPagedDataFetcher extends PagedDataFetcher {
    protected Vector get(int from, int to) throws Exception {
        return DataAccess.getDataAccess().getLists(from, to);
    }
}


/**
 * layout for list
 */
final class VList extends VerticalFieldManager {
    private final ObjectListField list;
    int maxHeight = Display.getHeight() - getFont().getHeight() * 2 - 5; 

    VList(ObjectListField list) {
        super(Manager.VERTICAL_SCROLLBAR | Manager.VERTICAL_SCROLL);
        this.list = list;
    }

    public int getPreferredHeight() {
        return 45 * list.getSize();
    }

    protected void sublayout(int width, int height) {
        super.sublayout(width, height);
        setExtent(width, maxHeight);
    }
}

1 个答案:

答案 0 :(得分:0)

如果你在measureRowList中得到一个NullPointerException,我看的第一个地方就是该方法的来源,以查看哪个空值被解除引用。看起来你没有包含该方法的来源。