简体   繁体   中英

Android Eclipse Java debugging issue about recognizing null object comparison

I've found a very strange behavior while debugging an Android application at the following code:

private String process(byte[] item) {
    if(item == null) {
        item = new byte[0];
    }

    //byte val = item[0];       
    //String str = "Val = " + Integer.toString(val);        
    //Log.e(TAG, str);
    [...]
    return rez;
}

Sometimes, while debugging, the execution steps inside the 'IF' block when 'ITEM' is a non-null variable. What's worse is that Eclipse's Expressions view actually lists 'ITEM' as non-null, allocated variable, and 'item == null' as false. This seems to happen as long as the commented lines stay commented, and it happens both on the sim and the device.

Any ideas what is going on ?

I am using Eclipse 3.7.1, latest Android SDK, and various 1.6+ sims and 2.1+ devices.

try

if(item==null)

(without the spaces). It worked for me.

edit the error has come back after another change in the lay-out of the program (ie by removing a comment)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM