我有一个基于参数返回位图对象的方法。 if条件没有执行,我不知道究竟是什么问题,我试图在if条件中打印Log语句,这是不行的
public static Bitmap getWesternZodiacIcon(Context context,String westernZodiacSign)throws Exception{
//Context context = null;
Bitmap westernZodiacIcon = null;
if (westernZodiacSign.equals("Aries")) {
westernZodiacIcon=BitmapFactory.decodeResource(context.getResources(),R.drawable.zodiac_aries);
Log.v("westernZodiacIcon", "westernZodiacSign");
}
else if (westernZodiacSign.equals("Taurus")) {
westernZodiacIcon=BitmapFactory.decodeResource(context.getResources(),R.drawable.zodiac_taurus);
Log.v("westernZodiacIcon", westernZodiacSign);
}
else if (westernZodiacSign.equals("Gemini")) {
westernZodiacIcon=BitmapFactory.decodeResource(context.getResources(),R.drawable.zodiac_gemini);
Log.v("westernZodiacIcon", westernZodiacSign);
}
else if (westernZodiacSign.equals("Cancer")) {
westernZodiacIcon=BitmapFactory.decodeResource(context.getResources(),R.drawable.zodiac_cancer);
Log.v("westernZodiacIcon", westernZodiacSign);
}
else if (westernZodiacSign.equals("Leo")) {
westernZodiacIcon=BitmapFactory.decodeResource(context.getResources(),R.drawable.zodiac_lion);
Log.v("westernZodiacIcon", westernZodiacSign);
}
else if (westernZodiacSign.equals("Virgo")) {
westernZodiacIcon=BitmapFactory.decodeResource(context.getResources(),R.drawable.zodiac_virgin);
Log.v("westernZodiacIcon", westernZodiacSign);
}
else if (westernZodiacSign.equals("Libra")) {
westernZodiacIcon=BitmapFactory.decodeResource(context.getResources(),R.drawable.zodiac_scales);
Log.v("westernZodiacIcon", westernZodiacSign);
}
else if (westernZodiacSign.equals("Scorpio")) {
westernZodiacIcon=BitmapFactory.decodeResource(context.getResources(),R.drawable.zodiac_scorpion);
Log.v("westernZodiacIcon", westernZodiacSign);
}
else if (westernZodiacSign.equals("Sagittarius")) {
westernZodiacIcon=BitmapFactory.decodeResource(context.getResources(),R.drawable.zodiac_sagittarius);
Log.v("westernZodiacIcon", westernZodiacSign);
}
else if (westernZodiacSign.equals("Capricorn")) {
westernZodiacIcon=BitmapFactory.decodeResource(context.getResources(),R.drawable.zodiac_capricor);
Log.v("westernZodiacIcon", westernZodiacSign);
}
else if (westernZodiacSign.equals("Aquarius")) {
westernZodiacIcon=BitmapFactory.decodeResource(context.getResources(),R.drawable.zodiac_aquarius);
Log.v("westernZodiacIcon", westernZodiacSign);
}
else if (westernZodiacSign.equals("Pisces")) {
westernZodiacIcon=BitmapFactory.decodeResource(context.getResources(),R.drawable.zodiac_pisces);
Log.v("westernZodiacIcon", westernZodiacSign);
}
return westernZodiacIcon;
}
答案 0 :(得分:0)
您必须考虑所有案例。添加其他:
...
else if (westernZodiacSign.equals("Pisces")) {
westernZodiacIcon=BitmapFactory.decodeResource(context.getResources(),R.drawable.zodiac_pisces);
Log.v("westernZodiacIcon", westernZodiacSign);
}
else {
Log.v("westernZodiacIcon", "The null hypothesis for astrology is...");
}
另外,如方法签名中所示,可能会抛出异常,因此请尝试捕获并记录日志。