2

I'm trying to override getItemViewType and return a different view type for my footer, but integer comparison is failing within the function:

enter image description here

This image shows a debug session where the input position is 21 and the the private List mValues has a size of 21, however when I pushed "step over" the conditional code is skipped.

If both integers are equal, why does position == mValues.size() return false?

I cleaned and rebuilt my project before running.

UPDATE:

It works when the integers are hardcoded:

enter image description here

but not when I use the input parameter:

enter image description here

UPDATE

I added a Log statement as the first line of the function

Log.e("MYAPP", "position: " + position + ", evaluates: " + (position == 21)); 

and in my monitor I see: position: 21, evaluates: true

However, my breakpoint at return FOOTER_VIEW; is never called and none of the functions related to the footer view are ever called.

UPDATE:

Heres the full Adaptor: https://gist.github.com/fergusom/79c6d5d9b1fd5e8348949d114a0159d5

Note that I updated the code to compute a boolean first, but it still fails even though the boolean prints out true in the logs

24
  • 1
    What type is mValues (runtime type)? Did you try stepping into mValues.size()? Can you verify that it returns 21? Commented Sep 2, 2016 at 16:12
  • If I replace mValues.size() with 21, it still fails, added a picture that shows this Commented Sep 2, 2016 at 16:14
  • 5
    Don't trust the debugger! Put logs statements inside and outside the if. Commented Sep 2, 2016 at 16:16
  • 1
    The debugger may highlight the wrong line because of code optimizations. Commented Sep 2, 2016 at 16:18
  • 1
    what is mValues actually? Commented Sep 2, 2016 at 16:25

2 Answers 2

1

Give the jvm no chance:

if(new Integer(position).equals(new Integer(mValues.size())) 

If the Integer constructor fails you'll know what the values were in the exception

Sign up to request clarification or add additional context in comments.

3 Comments

I tried going one step further and creating a boolean to use in the conditional and it still failed even when the boolean prints out true in a log. check out the full gist in the last update
Wait what? You printed a boolean variable, gives you true and it doesn't goes in the if statement?
yes. seems to have been a glitch on my device. I restarted my phone and its working now
1

I restarted my phone and it started working...

1 Comment

that was entertaining :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.