Incompatible types in string
Resources r1 = getRes开发者_如何学JAVAources();
String[] refrigerant = r1.getStringArray(R.array.refrigerant);
if (refrigerant == "")
{
if (et1.getText().toString() == refrigerant[i3]
{
flag = true;
}
I got the error incompatible operand types String[] and string please give me solution.
refrigerant is an array, but here refrigerant == "" you compare and array with "", which is not possible. You could check for null and refrigerant.length >0
If refrigerant is an String array you can not compare it as an empty String.
Try
if(refrigerant == null || refrigerant.length == 0){
}
Note also that comparing Strings using ==
as in your second if
clause will very often not work, as it tests object identity. You usually want to use string1.equals(string2)
.
looks like you are trying to compare a string array to a string in your first "if" statement
精彩评论