drawBitmap context.getResource null

时间:2014-08-04 16:02:11

标签: android canvas nullpointerexception android-context

您好我正在尝试使用Bitmap设置图片,但我的上下文中有空点异常

这是我的代码。

public class Helper extends Activity {
//my code
private static Helper  _instance;

    public Helper() {
        _instance = this;
    }                                 

    public static Context getContext() {
        return _instance;
    }
//code
private static void draw(Canvas canvas, String letters, int tileColor,
            int textColor, int left, int top, int right, int bottom) {
//code
            canvas.drawBitmap(BitmapFactory.decodeResource(_instance.getResources(),
            R.drawable.wine), (right + left) / 2 - width / 2, (top + bottom)
            / 2 + rect.height() / 2, null);

}

我做错了什么?我的错误在 _instance.getResources()

1 个答案:

答案 0 :(得分:0)

我在我的方法中添加 上下文 解决了我的错误。

    private static void draw(Canvas canvas, String letters, int tileColor,
                int textColor, int left, int top, int right, int bottom, Context context) {
                   //my code

}

谢谢你们

相关问题