I do not understand what it is that I'm doing wrong, the code seems alright, I am trying to set a background image for a GridLayout, when I add the background code, I get an error, when I comment it out, it runs good in the simulator.. What am I doing wrong?
UPDATE
public class GFMScreen extends MainScreen {
VerticalFieldManager ver;
ButtonField submit;
HorizontalFieldManager hr;
private int phoneWidth = Display.getWidth();
private int cellHeight = Display.getHeight();
public GFMScreen() {
super(Manager.USE_ALL_WIDTH | Manager.NO_VERTICAL_SCROLL);
setTitle("Jonezing");
createGUI();
}
public void createGUI() {
try {
final Bitmap background = Bitmap.getBitmapResource("bg.png");
ver = new VerticalFieldManager(Manager.NO_HORIZONTAL_SCROLL
| VerticalFieldManager.NO_VERTICAL_SCROLL
| Manager.FIELD_VCENTER | USE_ALL_HEIGHT | USE_ALL_WIDTH) {
public void paint(Graphics g) {
Bitmap scaled = new Bitmap(phoneWidth, cellHeight);
background.scaleInto(scaled, Bitmap.SCALE_TO_FIT);
g.drawBitmap(0, 0, phoneWidth, cellHeight, scaled, 0, 0);
super.paint(g);
}
};
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// ver.setBackground(BackgroundFactory.createBitmapBackground(Bitmap
// .getBitmapResource("bg.png")));
ver = new VerticalFieldManager(Manager.NO_HORIZONTAL_SCROLL
| VerticalFieldManager.NO_VERTICAL_SCROLL
| Manager.FIELD_VCENTER | USE_ALL_HEIGHT | USE_ALL_WIDTH);
GridFieldManager grid = new GridFieldManager(4, 2,
Manager.FIELD_VCENTER | Manager.NO_VERTICAL_SCROLL);
grid.add(new BitmapField(Bitmap.getBitmapResource("english.png")));
grid.add(new BitmapField(Bitmap.getBitmapResource("yoruba.png")));
grid.add(new LabelField("English", Field.FOCUSABLE));
grid.add(new LabelField("Yoruba", Field.FOCUSABLE));
grid.add(new BitmapField(Bitmap.getBitmapResource("mp.png")));
grid.add(new BitmapField(Bitmap.getBitmapResource("about.png")));
grid.add(new LabelField("MP3s", Field.FOCUSABLE));
grid.add(new LabelField("About", Field.FOCUSABLE));
grid.setPadding(100, 0, 50, 100);
grid.setColumnPadding(100);
grid.setRowPadding(10);
ver.add(grid);
add(ver);
}
}
Thank you.