-4

i want to convert userid(string) to integer but app get to crashed why? if i removes converted method then no crashed but i want integer value what i do?

  public void onCreate() {
    // TODO Auto-generated method stub
    super.onCreate();
    handler = new Handler();
  }
  @Override
  protected void onHandleIntent(Intent intent) {
        Bundle extras = intent.getExtras();
       /**
        * Get stored session data userid from other class
        **/
        userid = "";
        session = new SessionManager(getApplicationContext());//<-- this 
        HashMap<String, String> user = session.getUserDetails();
        userid = user.get(SessionManager.KEY_userid);

        /*i want convert userid to int, when i try to 
          convert then app is carashed. pls help me what i am missing here*/

        Integer U_ID = Integer.valueOf(userid);
        if(U_ID >0){
            Toast.makeText(GcmMessageHandler.this, "new on id="+userid, Toast.LENGTH_LONG).show();
        }

if i removes convert function then app not crashed, but i want integer valued what i do?

Chirag Parmar
  • 830
  • 11
  • 24
user6405383
  • 148
  • 1
  • 1
  • 12

1 Answers1

1

EDIT:

if(userid != null && !userid.trim().isEmpty()){
     int  U_ID = Integer.parseInt(userid)
}
Chirag Parmar
  • 830
  • 11
  • 24
sasikumar
  • 11,797
  • 2
  • 26
  • 44