0

I am trying to convert an object from an object to an integer in java. These are the results I get with the following methods:

Object intObject = 50;
intObject: 50
intObject.toString(): 50
Integer.getInteger(intObject.toString()): null

I have no idea why I would get a null when converting the string of the object to an integer.

Here is the code that I am using:

    final Object temp = mCloudEntity.get(SaveAndLoadManager.TAG_TEST_INT);
    Log.i(TAG, "intObject: " + temp );  
    Log.i(TAG, "intObject.toString(): " + temp.toString()); 
    Log.i(TAG, "Integer.getInteger(intObject.toString()): " + Integer.getInteger(temp.toString()));
eBehbahani
  • 1,579
  • 5
  • 19
  • 41

1 Answers1

2

You should use

// Parses the string argument as a signed decimal integer
Integer.parseInt(intObject.toString()); 

instead of

// Determines the integer value of the system property with the specified name.
// (Hint: Not what you want)
Integer.getInteger(...) 
David Hofmann
  • 5,683
  • 12
  • 50
  • 78