user6405383 user6405383 - 2 months ago 11
Java Question

How to convert string to integer in android?

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
handler = new Handler();
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?



if(userid != null && !userid.trim().isEmpty()){
     int  U_ID = Integer.parseInt(userid)