Search code examples
androidandroid-gradle-plugindex

error: incomparable types: Object and int


The error occurs when I generate signed .apk file.

It shows two sources of errors. When I clicked "Jump into Source" these are the codes:

In app\src\main\java\com\app\name\drawer\DrawerFragment.java

for (int i = 0; i < Config.TITLES.length; i++) {
        //If there is a localized title available, use it
        Object title = Config.TITLES[i];
        if (title instanceof Integer && title != 0){
            data.add(getResources().getString((int) title));
        } else {
            data.add((String) title);
        }
    }
    return data;
}

And In app\src\main\java\com\app\name\adapter\NavigationAdapter.java

Object title = Config.TITLES[position];
    if (title instanceof Integer && title != 0){
        return mContext.getResources().getString((int) title);
    } else {
        return (String) title;
    }
}

*I'm a newbie in these kind of Things. Please Help.


Solution

  • I'm guessing this is the line where you're seeing the issue:

    if (title instanceof Integer && title != 0) {
    

    You need to cast title to an Integer to be able to do the comparison:

    if (title instanceof Integer && ((Integer)title) != 0) {