i am trying to delete an event from calendar so i am fetching the event id from the database and sending them to local calendar to delete them,
when i try to execute them it showing me error like
logcat
03-22 08:29:41.474 27018-27018/com.example.myapplication E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.myapplication, PID: 27018
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.myapplication/com.example.myapplication.Schedule_Delete}: java.lang.NumberFormatException: For input string: " "
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2984)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3045)
at android.app.ActivityThread.-wrap14(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1642)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6776)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1496)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1386)
Caused by: java.lang.NumberFormatException: For input string: " "
at java.lang.Long.parseLong(Long.java:432)
at java.lang.Long.parseLong(Long.java:485)
at com.example.myapplication.Schedule_Delete.Event_delete(Schedule_Delete.java:99)
at com.example.myapplication.Schedule_Delete.writeCalendarEvent(Schedule_Delete.java:76)
at com.example.myapplication.Schedule_Delete.onCreate(Schedule_Delete.java:36)
at android.app.Activity.performCreate(Activity.java:6956)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1126)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2927)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3045)
at android.app.ActivityThread.-wrap14(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1642)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6776)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1496)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1386)
android code
private void writeCalendarEvent ()
{
String jsonString = getIntent().getStringExtra("rootJson");
String data = "";
try {
JSONObject jsonRootObject = new JSONObject(jsonString);
JSONArray jsonArray = jsonRootObject.getJSONArray("NEW_SCHEDULE");
Event_id = new String[jsonArray.length()];
for (L = 0; L < jsonArray.length(); L++) {
JSONObject jsonObject = jsonArray.getJSONObject(L);
Event_id[L] = jsonObject.getString("Event_id");
Event_delete(Event_id[L]);
}
} catch (JSONException e)
{
e.printStackTrace();
}
}
private void Event_delete(String s)
{
String id;
if(s.equals(""))
{
Toast.makeText(context, "id is empty"+s, Toast.LENGTH_LONG).show();
}
else
{
Toast.makeText(context, "id"+s, Toast.LENGTH_LONG).show();
id=s;
long eventID = Long.parseLong(id);
ContentResolver cr = getContentResolver();
ContentValues values = new ContentValues();
Uri deleteUri = null;
deleteUri = ContentUris.withAppendedId(CalendarContract.Events.CONTENT_URI, eventID);
int rows = getContentResolver().delete(deleteUri, null, null);
Log.i("identifier", "Rows deleted: " + rows);
}
}
This is my code i fetching the event id from the database and using them to delete the event in the calendar
in the database i have no value for "Event_id[L]" so i try to put check in " private void Event_delete(String s)" and try to execute the function, but the problem is it not executinng the if part executing the else part and showing me this error
Caused by: java.lang.NumberFormatException: For input string: " "
at java.lang.Long.parseLong(Long.java:432)
at java.lang.Long.parseLong(Long.java:485)
at com.example.myapplication.Schedule_Delete.Event_delete(Schedule_Delete.java:99)
at com.example.myapplication.Schedule_Delete.writeCalendarEvent(Schedule_Delete.java:76)
at com.example.myapplication.Schedule_Delete.onCreate(Schedule_Delete.java:36)
can anyone help me to fix this error!