-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
  • 833
  • 11
  • 26
user6405383
  • 146
  • 1
  • 2
  • 13

1 Answers1

2

EDIT:

if(userid != null && !userid.trim().isEmpty()){
     int  U_ID = Integer.parseInt(userid)
}
Chirag Parmar
  • 833
  • 11
  • 26
sasikumar
  • 12,540
  • 3
  • 28
  • 48