Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
New Contributor
Posts: 2
Registered: ‎11-15-2010
My Device: Not Specified

Problem with ObjectListField

[ Edited ]

Hello I'm a beginner programmer blackberry.

Develop a project under the JDE 4.6.1.

Following problem.

I have a class (in part):

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; } }
Where, db_.getDataAccess () - database, getListCount - getting the number of items in the list, CustomerListItem - the structure of a list item
/ / To obtain the data

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

The problem should, if adding an item to the list of error NullPointerException in method measureListRow

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

/** * 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);
} }

Help solve the problem

 

Developer
Posts: 16,992
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Problem with ObjectListField

welcome to the support forums. please use the code tag to post sourcecode.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Posts: 92
Registered: ‎01-15-2009
My Device: Blackberry 9550

Re: Problem with ObjectListField

Hi. Check this line

 

super.set(new Object[db_.getDataAccess().getListCount()]);

 

you create object with array of nulls.

 

Regards, Dmitry.

Highlighted
New Contributor
Posts: 2
Registered: ‎11-15-2010
My Device: Not Specified

Re: Problem with ObjectListField

The problem is that the JDE 4.5 and it works. I understand that this "set" creates an empty array of the desired length and then using the "get" it receives from the database necessary elements