Good morning, I am using a String field called "fecha_ini" and it contains a date in the following format "01-02-2018". What I need is to add one day to this date, but for that first I have to cast it from String to Date if I'm not mistaken. To do the casting I tried the following, but it throws me error:
fecha_ini = "01-02-2018";
try
{
String fecha = fecha_ini;
SimpleDateFormat format1 = new SimpleDateFormat("dd-MM-aaaa");
java.util.Date dateOjb = format1.parse(fecha);
SimpleDateFormat format2 = new SimpleDateFormat("dd/MM/aaaa");
nuevaFecha = format2.format(dateOjb);
Toast.makeText(this,nuevaFecha , Toast.LENGTH_SHORT).show();
}catch(ParseException e){
}
The error is this:
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.String.length ()' on a null object reference
Am I doing it right or is there another easier way to convert the "date_ini" field to Date? To then be able to work with the result and add days.
Thank you very much.