本文介绍了错误:类型不兼容:布尔值无法转换为int的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到错误:不兼容的类型:在Android Studio中编译android应用时,布尔值无法转换为int 错误.问题仅在于一种方法.

I'm getting the error: incompatible types: boolean cannot be converted to int error while compiling the android app in Android Studio. The problem is in only one method.

private static int get_wx_inx(String str) {
    boolean equalsIgnoreCase = str.equalsIgnoreCase("木");
    int equalsIgnoreCase2 = str.equalsIgnoreCase("火");
    if (str.equalsIgnoreCase("土")) {
        equalsIgnoreCase2 = true;
    }
    if (str.equalsIgnoreCase("金")) {
        equalsIgnoreCase2 = 3;
    }
    return str.equalsIgnoreCase("水") ? 4 : equalsIgnoreCase2;
}

我不知道怎么了.您能帮我解决问题吗?预先感谢.

I don't know what could be wrong. Can you help me to figure out the problem. Thanks in advance.

推荐答案

您的问题尚不明确,但您可能希望这样做:

Your question is not bit clear but you might want this:

private static int get_wx_inx(String str) {
        if(str.equalsIgnoreCase("木")) {
            return 0;
        } else if(str.equalsIgnoreCase("火")) {
            return 1;
        }else if(str.equalsIgnoreCase("土")) {
            return 2;
        } else if(str.equalsIgnoreCase("金")) {
            return 3;
        } else if(str.equalsIgnoreCase("水")) {
            return 4;
        } else {
            return 0;// write default return here. If every condition goes false then this default will be return.
        }
    }

这篇关于错误:类型不兼容:布尔值无法转换为int的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-27 22:56
查看更多