I have a created a class that inherits from the Manager class that will act as a holder for four other abstract classes called AbstractColumn.
Imagine a table with 4 columns, the table itself is the main class, and each column is AbstractColumn.
I don’t understand why I would get this error.
Here are my classes.
The Main ColumnHolder.java class
package tec.expenses;
import net.rim.device.api.system.Bitmap;
import net.rim.device.api.ui.Manager;
import net.rim.device.api.ui.component.BitmapField;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.container.VerticalFieldManager;
import net.rim.device.api.ui.decor.Background;
import net.rim.device.api.ui.decor.BackgroundFactory;
public class ColumnHolderManager extends Manager{
private AbstractColumn Entry;
private AbstractColumn Category;
private AbstractColumn Date;
private AbstractColumn Amount;
protected ColumnHolderManager(long style){
super(style);
Background mainBackground = BackgroundFactory.createSolidBackground(0xEEEEEE);
setBackground(mainBackground);
AbstractColumn Entry = new AbstractColumn("Entry", NO_HORIZONTAL_SCROLL);
AbstractColumn Category = new AbstractColumn("Category", NO_HORIZONTAL_SCROLL);
AbstractColumn Date = new AbstractColumn("Date", NO_HORIZONTAL_SCROLL);
AbstractColumn Amount = new AbstractColumn("Amount", NO_HORIZONTAL_SCROLL);
add(Entry);
add(Category);
add(Date);
add(Amount);
}
protected void sublayout(int width, int height) {
/*layoutChild(this.Entry, 85, 50);
setPositionChild(this.Entry, 10, 10 );
layoutChild(this.Category, 85, 50);
setPositionChild(this.Category, 40, 0 );
layoutChild(this.Date, 85, 50);
setPositionChild(this.Date, 70, 0 );
layoutChild(this.Amount, 85, 50);
setPositionChild(this.Amount, 100, 0 );*/
setExtent(360, 203);
}
}
The abstract AbstractColumn class
package tec.expenses;
import net.rim.device.api.system.Bitmap;
import net.rim.device.api.ui.Manager;
import net.rim.device.api.ui.component.BitmapField;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.decor.Background;
import net.rim.device.api.ui.decor.BackgroundFactory;
public class AbstractColumn extends Manager {
LabelField labelHeader;
protected AbstractColumn(String header, long style){
super(style);
Background mainBackground = BackgroundFactory.createSolidBackground(0xCACACA);
setBackground(mainBackground);
this.labelHeader = new LabelField(header);
add(labelHeader);
}
protected void sublayout(int width, int height) {
layoutChild(labelHeader, 80, 30);
setPositionChild(labelHeader, 5, 5);
setExtent(90, 50);
}
}
As you can see the classes are very simple yet I cannot understand why I would get this error.
I’m making this application for Blackberry using Eclipse as the IDE.
When I comment out the Sublayout methods’ setPositionChild methods I no longer get the exception which means that in the constructor of the ColumnHolderManager class, creating the new AbstractColumn objects aren’t really getting created.
Any help?
In these lines:
you are creating and initializing local variables.
You want to be initializing your instance members. Like this:
Also, normal Java code style rules indicate that your members should start with a lower case letter: entry, category, date, amount.