Q:

getting number format exception?

I am facing a problem. I am receiving all contacts and their recent calldates but when i tried to convert the calldate to date format, it throws NumberFormatException when value of long =null. 
I want to know how can i convert all calldates to date format but if null occurs it does not convert it into date format..below is my code help plz..
    mCursor.moveToFirst();

              while(!mCursor.isAfterLast()) {
                 String calldate="";

                    JSONObject contact = new JSONObject();
                    JSONObject parentCont = new JSONObject();
                    SharedPreferences settings = getSharedPreferences(Sesssion.PREF_NAME,0);
                    settings.getBoolean("phnosaved", true);  
                String usernumber=      settings.getString(Sesssion.knumber,"hey" );
                     String name = mCursor.getString(mCursor.getColumnIndex(Phone.DISPLAY_NAME));
                     String number = mCursor.getString(mCursor.getColumnIndex(Phone.NUMBER));
                     String selection = android.provider.CallLog.Calls.NUMBER+"="+"\""+number+"\"";
                     Log.d("selection query", "selection"+selection);
                     String Order = android.provider.CallLog.Calls.DATE + " DESC";
                              Cursor managedCursor = managedQuery(CallLog.Calls.CONTENT_URI,null, selection,null, null); 

                              if (managedCursor.moveToFirst ()) {
                                  do {

                            calldate= managedCursor.getString (managedCursor.getColumnIndex (android.provider.CallLog.Calls.DATE));
                                  break;

                                  } while (managedCursor.moveToNext());

                              }

                  //String   callDate = managedCursor.getString(managedCursor.getColumnIndex(android.provider.CallLog.Calls.DATE));

                    Date callDayTime = new Date(Long.valueOf(calldate));

                    //String dateColumn = cursorcalllog.getString(cursorcalllog.getColumnIndex(CallLog.Calls.DATE));

                     Log.d("CONTACT", "Name: " + name + "| Number: " + number+"Recently Called"+callDayTime);

logcat:-

04-03 13:13:52.231: E/AndroidRuntime(16548): Caused by: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.socialize_us/com.example.socialize_us.PhoneBookActivity}: java.lang.NumberFormatException: Invalid long: ""
04-03 13:13:52.231: E/AndroidRuntime(16548):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2084)
04-03 13:13:52.231: E/AndroidRuntime(16548):    at android.app.ActivityThread.startActivityNow(ActivityThread.java:1924)
04-03 13:13:52.231: E/AndroidRuntime(16548):    at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:135)
04-03 13:13:52.231: E/AndroidRuntime(16548):    at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:347)

A:

The problem is  
Long.valueOf("")
will throw  an exception
so 
Before calling
 Date callDayTime = new Date(Long.valueOf(calldate));

make sure that calldate nor equals ""
like 
    if(!calldate.trim.equals("")) {    Date callDayTime = new Date(Long.valueOf(calldate));}

