I'm making an app, that is storing some dates in a SQLite db on an android device.
Currently, most of it works as intended, except for parsing the text string that i store the date as.
private final String ALARMS_COLUMN_TIME = "time";
Calendar cal = Calendar.getInstance();
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
String dateString = cursor.getString(cursor.getColumnIndex(ALARMS_COLUMN_TIME));
cal.setTime(dateFormat.parse(dateString));
The problem is that, even before compiling, it gives me a, seemingly syntax error, with the "unhandled exception java.text.ParseException".
the imports i'm using in that class are these:
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
I have tried with various Locales as well, as part of the SimpleDateFormat constructor, but it haven't made any difference.
What can be the cause of this unhandled exception, prior to compiling?
Thanks in advance,
Ronnie
It's not that a ParseException
is being thrown - the problem is that the compiler is complaining because you're calling parse
which can throw a ParseException
, and you're not handling it.
ParseException
is a checked exception, which means that if you call a method that is declared to throw it, then you either need to catch it yourself, or you need to declare that your method might throw it. (We can't tell from your code which of those you want to do. You might want to catch it and rethrown an unchecked exception, for example.)
See more on this question at Stackoverflow