android.database.sqlite.SQLiteException:没有这样的列:favorite1(代码1)

时间:2015-02-13 08:35:50

标签: java android sqlite

当我调试我的应用程序时出现错误,我无法真正找到我做错了什么,我真的不知道为什么有一个背后的最爱,希望有人可以给我一个提示,谢谢。<登记/> logcat的:

  

02-13 07:42:49.070 1331-1331 / me.knoxc.fdemo E / SQLiteLog:(1)没有这样的列:favorite1   02-13 07:42:49.082 1331-1331 / me.knoxc.fdemo E / AndroidRuntime:FATAL EXCEPTION:main       android.database.sqlite.SQLiteException:没有这样的列:favorite1(代码1):,同时编译:SELECT(SELECT COUNT()FROM条目WHERE isread IS NULL),(SELECT COUNT()FROM条目WHERE favorite1)FROM条目JOIN(SELECT _id AS joined_feed_id,name,url,icon,groupid FROM feeds)AS f ON(entries.feedid = f.joined_feed_id)               在android.database.sqlite.SQLiteConnection.nativePrepareStatement(本机方法)               在android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:889)               在android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:500)               在android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)               在android.database.sqlite.SQLiteProgram。(SQLiteProgram.java:58)               在android.database.sqlite.SQLiteQuery。(SQLiteQuery.java:37)               在android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:44)               在android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1314)               在android.database.sqlite.SQLiteQueryBuilder.query(SQLiteQueryBuilder.java:400)               在android.database.sqlite.SQLiteQueryBuilder.query(SQLiteQueryBuilder.java:294)               at me.knoxc.fdemo.provider.FeedDataContentProvider.query(FeedDataContentProvider.java:269)               在android.content.ContentProvider.query(ContentProvider.java:744)               在android.content.ContentProvider $ Transport.query(ContentProvider.java:199)               在android.content.ContentResolver.query(ContentResolver.java:414)               在android.content.ContentResolver.query(ContentResolver.java:357)               at me.knoxc.fdemo.adapter.DrawerAdapter.updateNumbers(DrawerAdapter.java:208)               at me.knoxc.fdemo.adapter.DrawerAdapter。(DrawerAdapter.java:60)               at me.knoxc.fdemo.activity.MainActivity.onLoadFinished(MainActivity.java:331)               at me.knoxc.fdemo.activity.MainActivity.onLoadFinished(MainActivity.java:39)               在android.app.LoaderManagerImpl $ LoaderInfo.callOnLoadFinished(LoaderManager.java:483)               在android.app.LoaderManagerImpl $ LoaderInfo.onLoadComplete(LoaderManager.java:451)               在android.content.Loader.deliverResult(Loader.java:144)               在android.content.CursorLoader.deliverResult(CursorLoader.java:110)               在android.content.CursorLoader.deliverResult(CursorLoader.java:43)               在android.content.AsyncTaskLoader.dispatchOnLoadComplete(AsyncTaskLoader.java:256)               在android.content.AsyncTaskLoader $ LoadTask.onPostExecute(AsyncTaskLoader.java:91)               在android.os.AsyncTask.finish(AsyncTask.java:631)               在android.os.AsyncTask.access $ 600(AsyncTask.java:177)               在android.os.AsyncTask $ InternalHandler.handleMessage(AsyncTask.java:644)               在android.os.Handler.dispatchMessage(Handler.java:99)               在android.os.Looper.loop(Looper.java:137)               在android.app.ActivityThread.main(ActivityThread.java:5103)               at java.lang.reflect.Method.invokeNative(Native Method)               在java.lang.reflect.Method.invoke(Method.java:525)               在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:737)               在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)               在dalvik.system.NativeStart.main(原生方法)

FeedDataContentProvider.java的密钥代码

public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
    SQLiteQueryBuilder queryBuilder = new SQLiteQueryBuilder();

    int matchCode = URI_MATCHER.match(uri);

    if ((matchCode == URI_FEEDS || matchCode == URI_GROUPS || matchCode == URI_FEEDS_FOR_GROUPS) && sortOrder == null) {
        sortOrder = FeedData.FeedColumns.PRIORITY;
    }

    switch (matchCode) {
        case URI_GROUPED_FEEDS: {
            queryBuilder.setTables(FeedData.FEEDS_TABLE_WITH_GROUP_PRIORITY);
            sortOrder = "IFNULL(group_priority, " + FeedData.FeedColumns.PRIORITY + "), IFNULL(" + FeedData.FeedColumns.GROUP_ID + ", " + FeedData.FeedColumns._ID + "), " + FeedData.FeedColumns.IS_GROUP + " DESC, " + FeedData.FeedColumns.PRIORITY;
            break;
        }
        case URI_GROUPS: {
            queryBuilder.setTables(FeedData.FeedColumns.TABLE_NAME);
            queryBuilder.appendWhere(new StringBuilder(FeedData.FeedColumns.IS_GROUP).append(Constants.DB_IS_TRUE).append(Constants.DB_OR)
                    .append(FeedData.FeedColumns.GROUP_ID).append(Constants.DB_IS_NULL));
            break;
        }
        case URI_FEEDS_FOR_GROUPS: {
            queryBuilder.setTables(FeedData.FeedColumns.TABLE_NAME);
            queryBuilder.appendWhere(new StringBuilder(FeedData.FeedColumns.GROUP_ID).append('=').append(uri.getPathSegments().get(1)));
            break;
        }
        case URI_GROUP:
        case URI_FEED: {
            queryBuilder.setTables(FeedData.FeedColumns.TABLE_NAME);
            queryBuilder.appendWhere(new StringBuilder(FeedData.FeedColumns._ID).append('=').append(uri.getPathSegments().get(1)));
            break;
        }
        case URI_FEEDS: {
            queryBuilder.setTables(FeedData.FeedColumns.TABLE_NAME);
            queryBuilder.appendWhere(new StringBuilder(FeedData.FeedColumns.IS_GROUP).append(Constants.DB_IS_NULL));
            break;
        }
        case URI_FILTERS: {
            queryBuilder.setTables(FeedData.FilterColumns.TABLE_NAME);
            break;
        }
        case URI_FILTERS_FOR_FEED: {
            queryBuilder.setTables(FeedData.FilterColumns.TABLE_NAME);
            queryBuilder.appendWhere(new StringBuilder(FeedData.FilterColumns.FEED_ID).append('=').append(uri.getPathSegments().get(1)));
            break;
        }
        case URI_ENTRY_FOR_FEED:
        case URI_ENTRY_FOR_GROUP:
        case URI_SEARCH_ENTRY: {
            queryBuilder.setTables(FeedData.ENTRIES_TABLE_WITH_FEED_INFO);
            queryBuilder.appendWhere(new StringBuilder(FeedData.EntryColumns._ID).append('=').append(uri.getPathSegments().get(3)));
            break;
        }
        case URI_ENTRIES_FOR_FEED: {
            queryBuilder.setTables(FeedData.ENTRIES_TABLE_WITH_FEED_INFO);
            queryBuilder.appendWhere(new StringBuilder(FeedData.EntryColumns.FEED_ID).append('=').append(uri.getPathSegments().get(1)));
            break;
        }
        case URI_ENTRIES_FOR_GROUP: {
            queryBuilder.setTables(FeedData.ENTRIES_TABLE_WITH_FEED_INFO);
            queryBuilder.appendWhere(new StringBuilder(FeedData.FeedColumns.GROUP_ID).append('=').append(uri.getPathSegments().get(1)));
            break;
        }
        case URI_ALL_ENTRIES:
        case URI_ENTRIES: {
            queryBuilder.setTables(FeedData.ENTRIES_TABLE_WITH_FEED_INFO);
            break;
        }
        case URI_SEARCH: {
            queryBuilder.setTables(FeedData.ENTRIES_TABLE_WITH_FEED_INFO);
            queryBuilder.appendWhere(getSearchWhereClause(uri.getPathSegments().get(2)));
            break;
        }
        case URI_FAVORITES_ENTRY:
        case URI_ALL_ENTRIES_ENTRY:
        case URI_ENTRY: {
            queryBuilder.setTables(FeedData.ENTRIES_TABLE_WITH_FEED_INFO);
            queryBuilder.appendWhere(new StringBuilder(FeedData.EntryColumns._ID).append('=').append(uri.getPathSegments().get(1)));
            break;
        }
        case URI_FAVORITES: {
            queryBuilder.setTables(FeedData.ENTRIES_TABLE_WITH_FEED_INFO);
            queryBuilder.appendWhere(new StringBuilder(FeedData.EntryColumns.IS_FAVORITE).append(Constants.DB_IS_TRUE));
            break;
        }
        case URI_TASKS: {
            queryBuilder.setTables(FeedData.TaskColumns.TABLE_NAME);
            break;
        }
        case URI_TASK: {
            queryBuilder.setTables(FeedData.TaskColumns.TABLE_NAME);
            queryBuilder.appendWhere(new StringBuilder(FeedData.EntryColumns._ID).append('=').append(uri.getPathSegments().get(1)));
            break;
        }
        default:
            throw new IllegalArgumentException("Illegal query. Match code=" + matchCode + "; uri=" + uri);
    }

    SQLiteDatabase database = mDatabaseHelper.getReadableDatabase();

    Cursor cursor = queryBuilder.query(database, projection, selection, selectionArgs, null, null, sortOrder);

    cursor.setNotificationUri(getContext().getContentResolver(), uri);
    return cursor;
}<br>

FeedData.java的密钥代码

public static class EntryColumns implements BaseColumns {
    public static final String TABLE_NAME = "entries";

    public static final String FEED_ID = "feedid";
    public static final String TITLE = "title";
    public static final String ABSTRACT = "abstract";
    public static final String MOBILIZED_HTML = "mobilized";
    public static final String DATE = "date";
    public static final String FETCH_DATE = "fetch_date";
    public static final String IS_READ = "isread";
    public static final String LINK = "link";
    public static final String IS_FAVORITE = "favorite";
    public static final String ENCLOSURE = "enclosure";
    public static final String GUID = "guid";
    public static final String AUTHOR = "author";
    public static final String IMAGE_URL = "image_url";
    public static final String[] PROJECTION_ID = new String[]{EntryColumns._ID};
    public static final String WHERE_READ = EntryColumns.IS_READ + Constants.DB_IS_TRUE;
    public static final String WHERE_UNREAD = "(" + EntryColumns.IS_READ + Constants.DB_IS_NULL + Constants.DB_OR + EntryColumns.IS_READ + Constants.DB_IS_FALSE + ')';
    public static final String[][] COLUMNS = new String[][]{{_ID, TYPE_PRIMARY_KEY}, {FEED_ID, TYPE_EXTERNAL_ID}, {TITLE, TYPE_TEXT},
            {ABSTRACT, TYPE_TEXT}, {MOBILIZED_HTML, TYPE_TEXT}, {DATE, TYPE_DATE_TIME}, {FETCH_DATE, TYPE_DATE_TIME}, {IS_READ, TYPE_BOOLEAN}, {LINK, TYPE_TEXT},
            {IS_FAVORITE, TYPE_BOOLEAN}, {ENCLOSURE, TYPE_TEXT}, {GUID, TYPE_TEXT}, {AUTHOR, TYPE_TEXT}, {IMAGE_URL, TYPE_TEXT}};
    public static final String WHERE_NOT_FAVORITE = "(" + EntryColumns.IS_FAVORITE + Constants.DB_IS_NULL + Constants.DB_OR + EntryColumns.IS_FAVORITE + Constants.DB_IS_FALSE + ')';

    public static Uri ENTRIES_FOR_FEED_CONTENT_URI(String feedId) {
        return Uri.parse(CONTENT_AUTHORITY + "/feeds/" + feedId + "/entries");
    }

    public static Uri ENTRIES_FOR_FEED_CONTENT_URI(long feedId) {
        return Uri.parse(CONTENT_AUTHORITY + "/feeds/" + feedId + "/entries");
    }

    public static final Uri CONTENT_URI = Uri.parse(CONTENT_AUTHORITY + "/entries");

    public static Uri ENTRIES_FOR_GROUP_CONTENT_URI(String groupId) {
        return Uri.parse(CONTENT_AUTHORITY + "/groups/" + groupId + "/entries");
    }

    public static Uri ENTRIES_FOR_GROUP_CONTENT_URI(long groupId) {
        return Uri.parse(CONTENT_AUTHORITY + "/groups/" + groupId + "/entries");
    }

    public static Uri ALL_ENTRIES_CONTENT_URI(String entryId) {
        return Uri.parse(CONTENT_AUTHORITY + "/all_entries/" + entryId);
    }

    public static final Uri ALL_ENTRIES_CONTENT_URI = Uri.parse(CONTENT_AUTHORITY + "/all_entries");

    public static Uri CONTENT_URI(String entryId) {
        return Uri.parse(CONTENT_AUTHORITY + "/entries/" + entryId);
    }

    public static Uri CONTENT_URI(long entryId) {
        return Uri.parse(CONTENT_AUTHORITY + "/entries/" + entryId);
    }

    public static Uri PARENT_URI(String path) {
        return Uri.parse(CONTENT_AUTHORITY + path.substring(0, path.lastIndexOf('/')));
    }

    public static final Uri FAVORITES_CONTENT_URI = Uri.parse(CONTENT_AUTHORITY + "/favorites");

    public static Uri SEARCH_URI(String search) {
        return Uri.parse(CONTENT_AUTHORITY + "/entries/search/" + (TextUtils.isEmpty(search) ? " " : Uri.encode(search))); // The space is mandatory here with empty search
    }


}

2 个答案:

答案 0 :(得分:1)

也许这就是罪魁祸首:

case URI_FAVORITES: {
         // .....
         queryBuilder.appendWhere(new StringBuilder(FeedData.EntryColumns.IS_FAVORITE).append(Constants.DB_IS_TRUE));
         break;
}

Constants.DB_IS_TRUE等于什么?

无论它是平等的,在这种情况下我认为“1”,它会被附加到“最喜欢的”列名,并产生“favorite1”。

答案 1 :(得分:0)

case URI_FAVORITES: {
     // .....
     queryBuilder.appendWhere(new StringBuilder(FeedData.EntryColumns.IS_FAVORITE)

.append("=") //add this line

.append(Constants.DB_IS_TRUE));
     break;
}