android - 如何从子类中获取可绘制资源?
问题描述
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;
}
}
}
解决方案
你不需要ContextCompat.getDrawable
从资源中获取drawable
只需使用这个
nous_jeux_1.setImageResource(R.drawable.bulle_pleine);
推荐阅读
- unity3d - 如何统一重复碰撞?
- apache-spark - 如何将数组传递给 Spark (UDAF) 中的用户定义聚合函数
- javascript - 过滤键并减少为嵌套结构
- java - MapStruct / Java - 将时间戳转换为即时
- javascript - 如何在不裁剪的情况下保存图像?
- json - 为什么我不能在 Postgres 中聚合 setof jsonb?
- python - 如何从嵌套列表和字典中读取字典键和值
- python - Firebase / Google Cloud Function 中的 HTTP 请求多次返回
- sql-server - 获取余额为负数的天数
- typescript - TestCafe - 检查超链接是否正常工作 - 重定向到外部电子邮件提供商