I'm experiencing a nullpointerexception in my android java code in the following code. This is inside AndroidGraphics.java.
public void drawPixmap(Pixmap pixmap, int x, int y) {
canvas.drawBitmap(((AndroidPixmap)pixmap).bitmap, x, y, null);
}
AndroidPixmap.java is here:
package com.badlogic.androidgames.framework.impl;
import android.graphics.Bitmap;
import com.badlogic.androidgames.framework.Graphics.PixmapFormat;
import com.badlogic.androidgames.framework.Pixmap;
public class AndroidPixmap implements Pixmap{
Bitmap bitmap;
PixmapFormat format;
public AndroidPixmap(Bitmap bitmap, PixmapFormat format){
this.bitmap = bitmap;
this.format = format;
}
@Override
public int getWidth(){
return bitmap.getWidth();
}
@Override
public int getHeight(){
return bitmap.getHeight();
}
@Override
public PixmapFormat getFormat(){
return format;
}
@Override
public void dispose(){
bitmap.recycle();
}
}
Is there something wrong with the casting? Any help would be great!
EDIT: This is the pixmap class:
package com.badlogic.androidgames.framework;
import com.badlogic.androidgames.framework.Graphics.PixmapFormat;
public interface Pixmap {
public int getWidth();
public int getHeight();
public PixmapFormat getFormat();
public void dispose();
}
Your AndroidPixmap implements Pixmap, it is not inherited/extended from Pixmap. If you cast to Pixmap, you get the Implementation only, which I assume has bitmap=null. As you didn't add the Pixmap class to the question, it's quite hard to answer in more detail.