Android 数组初始化错误:维表达式与初始化冲突的解决方法
在Android中,同时使用维表达式和初始化创建数组是非法的。要解决这个问题,你可以将初始化代码分别放到不同的语句中,例如:
controlModeIcon=new Drawable[4][2];
controlModeIcon[0][0] = ContextCompat.getDrawable(this,R.drawable.cold_black);
controlModeIcon[0][1] = ContextCompat.getDrawable(this,R.drawable.cold_white);
controlModeIcon[1][0] = ContextCompat.getDrawable(this,R.drawable.cold_black);
controlModeIcon[1][1] = ContextCompat.getDrawable(this,R.drawable.cold_white);
controlModeIcon[2][0] = ContextCompat.getDrawable(this,R.drawable.cold_black);
controlModeIcon[2][1] = ContextCompat.getDrawable(this,R.drawable.cold_white);
controlModeIcon[3][0] = ContextCompat.getDrawable(this,R.drawable.cold_black);
controlModeIcon[3][1] = ContextCompat.getDrawable(this,R.drawable.cold_white);
这样,你就可以将初始化代码分配到不同的语句中,而不会出现错误。
原文地址: https://www.cveoy.top/t/topic/oysX 著作权归作者所有。请勿转载和采集!