我正在使用AsyncQueryHandler
在SQLite数据库中插入一行,并尝试在id
方法中获取新插入行的onInsertComplete
,如try-catch
所示,但是我得到例外:java.lang.NullPointerException: unable to parse 'lectureTimeTable' (this is my table name in which i have inserted a row.)
我正在关注This StackOverflow question.
我想知道在以下情况下获取最后插入行的id的方法!
AsyncQueryHandler mAsyncQueryHandler = new AsyncQueryHandler(getContentResolver()) {
@Override
protected void onInsertComplete(int token, Object cookie, Uri uri) {
super.onInsertComplete(token, cookie, uri);
switch (token) {
case MyConstants.TOKEN_INSERT_LECTURE_TIME:
try {
int newlyInsertedLectureTimeId = Integer.valueOf(uri
.getLastPathSegment());
} catch (Exception e) {
e.printStackTrace();
}
default:
break;
}
}
};
mAsyncQueryHandler.startInsert(
MyConstants.TOKEN_INSERT_LECTURE_TIME, new Object(),
CourseLectureTime.CONTENT_URI, lectureTimeCV);