Java tutorial
//package com.java2s; import android.text.TextUtils; public class Main { public static long obj2Long(Object obj) { if (obj == null) return 0L; return str2Long(obj.toString(), 0L); } public static long str2Long(String obj, Long defValue) { try { if (TextUtils.isEmpty(obj)) return defValue; return Long.parseLong(obj); } catch (Exception e) { e.printStackTrace(); } return defValue; } }