安卓奇葩问题之:运行OK,打包安装崩溃(原因是:代码不规范导致编译出错)

时间:2021-07-10 14:56:52

咳咳,还是那句话,真是日了狗了

这个问题真的很难找,废话不多少,上酸菜。

报错信息是这个方法返回的图片找不到

public static int getImgID(boolean isBig, int id) {
if (id == -2)
return R.mipmap.tianjia;
if (id == -1)
return R.mipmap.jiahao;
if (isBig) {
switch (id) {
case 0:
return R.mipmap.jrfu;
case 1:
return R.mipmap.meishi;
case 2:
return R.mipmap.shenghuo;
case 3:
return R.mipmap.yule;
case 4:
return R.mipmap.dying;
case 5:
return R.mipmap.chuxing;
case 6:
return R.mipmap.jingdian;
case 7:
return R.mipmap.gouwu;
case 8:
return R.mipmap.jiudian;
case 9:
return R.mipmap.zhiyuan;
case 10:
return R.mipmap.xsyl;
case 11:
return R.mipmap.jrfu;
}
return R.mipmap.guanggao;
} else {
switch (id) {
case 0:
return R.mipmap.jrfw;
case 1:
return R.mipmap.ms;
case 2:
return R.mipmap.shfw;
case 3:
return R.mipmap.yl;
case 4:
return R.mipmap.dy;
case 5:
return R.mipmap.cx;
case 6:
return R.mipmap.jingdian_xiao;
case 7:
return R.mipmap.gw;
case 8:
return R.mipmap.jd;
case 9:
return R.mipmap.zyhn_xiao;
case 10:
return R.mipmap.xsyl_xiao;
case 11:
return R.mipmap.jrfw;
}
return R.mipmap.logo;
}
}

问题来了,运行代码是OK的。

然后天空一声巨响,醍醐灌顶。代码写的不规范,没有用break,编译有问题,才会报错的。