Skip to content Skip to sidebar Skip to footer

How To Use Stringutils And Mystring, Getting Cannot Resolve Error

Running the below code and can't resolve StringUtils and myString... does something need imported or is there another way? this takes a string from another activity and makes it an

Solution 1:

The most of safe way is used to try {} catch {} block like code below

Integer oldValue;
try{
 oldValue= Integer.parseInt(myString);
}catch(NumberFormatException e){
  oldValue =0;
}

instead of :

Integer oldValue = StringUtils.isNotBlank(myString) ? Integer.parseInt(myString) : 0;

Solution 2:

To add to Konrad's answer:

You should include all your code...

if you are trying to Get a String from a previous Activity then parse it to an Integer, Why not just pass it as an int And do something like:

Declare class level variable

privateint mPassedInValue;

protectedvoidonCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

 // Get the Extras Bundle from the IntentBundlepreviousIntentExtras= getIntent().getExtras();

 // Check to make sure this is not nullif(previousIntentExtras != null){
    mPassedInValue = previousIntentExtras.getInt("MyInt",0);

  /* ... Perform the function you want to do since the value you passed in is
   * Is already in the correct form...
   */ 

 }

} 

Post a Comment for "How To Use Stringutils And Mystring, Getting Cannot Resolve Error"