如何从子类中获取可绘制资源?

时间:2019-04-16 07:51:41

标签: android

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

这是给Android穿戴的

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;
            }


    }
}

1 个答案:

答案 0 :(得分:0)

您不需要ContextCompat.getDrawable即可从资源中获取图片

只需使用

nous_jeux_1.setImageResource(R.drawable.bulle_pleine);