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.

4 Answers 4

1

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

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

1 Comment

so, use Integer.parseInt(String.valueOf(<your variable>)) this will work on Object type
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.

8 Comments

Check screen 1, it is an object with count 2 i.e. "3" and "1"
that's not "3" and "1". That's "31 ". That's a lot different.
No, it's because you can't cast a string to an integer.
That's why I've put Integer.parseInt() in my solution.
As I mentioned, feedArray.get(mJazzy.getCurrentItem()).get("TotalCount_Smasheys") gives me Object not String.
|
0

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

int i = Integer.valueOf((String) your_object);

Comments

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);

5 Comments

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?
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.
Did you try my answer?
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.
The problem is that the Object can be anything, String or Integer. If it returns Integer, then it will cause error here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.