如何使用AsynQueryHandler获取SQLite数据库中最后一个插入行的id

时间:2013-06-21 19:32:39

标签: android android-contentprovider

我正在使用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);

0 个答案:

没有答案