0

I am getting this error, but don't know why. Here

feedArray.get(mJazzy.getCurrentItem()).get("TotalCount_Smasheys") 

returns an Object type. I followed this link to cast Object to Integer.

Screen 1: Here I inspected:

feedArray.get(mJazzy.getCurrentItem()).get("TotalCount_Smasheys") 

and got value:

screen 1

Screen 2: Here I inspected: (Integer)(feedArray.get(mJazzy.getCurrentItem()).get("TotalCount_Smasheys")) and it throws exception:

screen 2

EDIT: It is very confusing. feedArray.get(mJazzy.getCurrentItem()).get("TotalCount_Smasheys") returns me an Object, which is actually an Integer, so I can't use (String) on it.

Community
  • 1
  • 1
berserk
  • 2,690
  • 3
  • 32
  • 63

4 Answers4

1

first use String.trim() Then, instead of casting to Integer Use Integer.parseInt() or Integer.valueOf()
It'll might help.

Kasim Rangwala
  • 1,765
  • 2
  • 23
  • 44
0

That's because the string has spaces. Remove the spaces from the string first and then use Integer.parseInt() to change it to integer.

You can use string.trim() or string.replace(" ","") to remove whitespaces.

Pedro Oliveira
  • 20,442
  • 8
  • 55
  • 82
0

It lloks like "31" is not an integer but a string. Did you try

int i = Integer.valueOf((String) your_object);
yrazlik
  • 10,411
  • 33
  • 99
  • 165
0

The method

feedArray.get(mJazzy.getCurrentItem()).get("TotalCount_Smasheys")

is returning a String, not an Integer.

Convert it to integer using Integer.parseInt():

String countString = (String) feedArray.get(mJazzy.getCurrentItem()).get("TotalCount_Smasheys");
Integer countInt = Integer.parseInt(countString);
Guilherme
  • 7,839
  • 9
  • 56
  • 99
  • It clearly is not an `Integer` otherwise it wouldn't crash that way. Did you try my answer? What error did you get using it? – Guilherme Sep 26 '14 at 12:35
  • Actually feedArray is an ArrayList of type ParseObject. And ParseObject.get("key") returns an "Object", not an Integer. But the value is actually an Integer, so the Object it returns automatically becomes Integer. Hope u understand what I said lol. – berserk Sep 26 '14 at 13:50
  • Did you try my answer? – Guilherme Sep 26 '14 at 14:24
  • Ok, you need to do what Eclipse is suggesting (and I also forgot to do, sorry for that): cast the string. I've updated my answer. – Guilherme Sep 26 '14 at 17:51
  • The problem is that the Object can be anything, String or Integer. If it returns Integer, then it will cause error here. – berserk Sep 28 '14 at 08:58