2

我正在使用 SQLite DB 在 SQLite DB 中插入一行,AsyncQueryHandler并尝试id在方法中获取新插入的行onInsertComplete,如下所示,try-catch但我遇到了异常:java.lang.NullPointerException: unable to parse 'lectureTimeTable' (this is my table name in which i have inserted a row.)

我正在关注这个 StackOverflow 问题。

我想知道在以下情况下获取最后插入行的 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);
4

0 回答 0