sGF sGF - 2 years ago 102
Android Question

Not a statetment (Compiler Error Java/Android)

I am trying to do a simple if Statement using the ? pattern. Resulting in an "Not a statement"- Error. Can someone please explain to me why this bullshit is not happening using a normal if statement?


cursor.isNull(0) ? insert_SQL_RSServer.bindNull(0) : insert_SQL_RSServer.bindLong(0, cursor.getLong(0)); // id

No Error:

insert_SQL_RSServer.bindLong(0, cursor.getLong(0));

This is completely the same behavior ....

Answer Source

The ternary conditional operator is an expression, and it must have a return type, which is determined by the types of the 2nd and 3rd operands.

Therefore, if your bindNull() and bindLong() methods have void return type, they can't be used in this operator.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download