I am adding three bitmap in my screen.The image needs to change with focus and unfocus.Now if i declare the bitmaps inside my customised method,than wheni scroll from one image to another,it gives null pointer exception.But when i declare the bitmaps outside the method,i dont get any exception,but only the last focused image gets focused everywhere,but it should be like that for three images three seperate focused images are there.Below is my code.Please help.
private BitmapField getBitmapField(final Item item, final int cellWid, final int cellHgt, final long style) {
final Bitmap bitmap = Bitmap.getBitmapResource(item.imgUrl);
final Bitmap bitmapfoc = Bitmap.getBitmapResource(item.imgUrlimp);
BitmapField bitmapField = new BitmapField(bitmap, style) {
boolean _inFocus = false;
protected void onFocus(int direction) {
_inFocus = true;
selectedIndex = flowFieldManager.getFieldWithFocusIndex();
System.out.println("Selected Index :"+selectedIndex);
if(TextControl.labelField != null)
TextControl.labelField.setText(item.title);
super.onFocus(direction);
//this.invalidate();
}
protected void onUnfocus() {
_inFocus = false;
super.onUnfocus();
//this.invalidate();
}
public void paint(Graphics graphics) {
System.out.println("====barView=== :"+barview);
graphics.drawBitmap(0, 0, bitmap.getWidth(),bitmap.getHeight(), bitmap, 0, 0); //draw bachground image bitmap
invalidate();
//super.paint(graphics);
}
protected void drawFocus(Graphics g, boolean arg1) {
g.drawBitmap(0,0, bitmapfoc.getWidth(), bitmapfoc.getHeight(), bitmapfoc, 0, 0); //draw bachground image bitmap
invalidate();
}
invalidate()from inside of a painting method sinceinvalidate()signifies it needs to repaint. Can you give us any helpful info, like where the NPE is getting thrown? - jprofitt