首页 > 解决方案 > 如何从子类中获取可绘制资源?

问题描述

Firstable 对不起我的英语不好,在一个子类中我想获得一个可绘制的资源,但是出现一个错误,比如 nullObjectRefernce。我不知道如何解决这个问题。如果有人可以帮助我。谢谢!

这是安卓穿戴

public class DisplayManager extends MainActivity {

    private Drawable bulle_pleine;
    private int point;
    private String[] tabScore = {"0", "15", "30", "40", "EG", "AV","Jeu"};


    public void updateDisplayPoint(String player, int pt) {
        if (player == "nous") {
            btn_nous.setText(tabScore[pt]);
        }else{
            btn_eux.setText(tabScore[pt]);
        }
    }

    public void updateDisplayGame(String player, int ptGame) {
        Log.i("ptGame ", String.valueOf(ptGame));
        if (player == "nous") {
            switch (ptGame) {
                case 1:
                    bulle_pleine = ContextCompat.getDrawable(getApplicationContext(), R.drawable.bulle_pleine);
                    nous_jeux_1.setImageDrawable(bulle_pleine);
                    break;
            }


    }
}

标签: android

解决方案


你不需要ContextCompat.getDrawable从资源中获取drawable

只需使用这个

nous_jeux_1.setImageResource(R.drawable.bulle_pleine);

推荐阅读