-4

how to solve this problem error: bad operand types for binary operator '*' ?

this is my code :

  int minimal = (Integer.parseInt(TextUtils.isEmpty(listData.get(position).getMinimal()) ? "0" : listData.get(position).getMinimal()))
            *(TextUtils.isEmpty(listData.get(position).getQuantity()) ? "0" : listData.get(position).getQuantity());

this is the error : Error:(80, 17) error: bad operand types for binary operator '*'

first type: int

second type: String

Can someone help me? I'm new to android studio and this is my first time working with it. Thanks in advance for your time. :)

Agien Farhan
  • 3
  • 2
  • 5
  • 5
    Please don't write such convoluted code. It's too long to read, and it's too complex to understand. Extract into variables and you will find what the problem is. – Henry Dec 28 '17 at 05:05
  • Please format the code and share the complete error. – akash Dec 28 '17 at 05:09

1 Answers1

1

Your second operand is still String . Do it this way.

 int minimal = Integer.parseInt(TextUtils.isEmpty(listData.get(position).getMinimal()) ? "0" : listData.get(position).getMinimal())
            *Integer.parseInt(TextUtils.isEmpty(listData.get(position).getQuantity()) ? "0" : listData.get(position).getQuantity());

its complex so you can simply use primitive variable can be readable easily.

int opA=Integer.parseInt(TextUtils.isEmpty(listData.get(position).getMinimal()) ? "0" : listData.get(position).getMinimal());
    int opB=Integer.parseInt(TextUtils.isEmpty(listData.get(position).getQuantity()) ? "0" : listData.get(position).getQuantity());
    int minimal=opA*opB;
ADM
  • 20,406
  • 11
  • 52
  • 83