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

时间:2015-02-28 09:17:07

标签: android sqlite

02-28 14:35:52.946    1923-1937/com.example.android.sunshine.app E/AndroidRuntime﹕ FATAL EXCEPTION: ModernAsyncTask #1
    Process: com.example.android.sunshine.app, PID: 1923
    java.lang.RuntimeException: An error occured while executing doInBackground()
            at android.support.v4.content.ModernAsyncTask$3.done(ModernAsyncTask.java:137)
            at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
            at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
            at java.util.concurrent.FutureTask.run(FutureTask.java:242)
            at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
            at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
            at java.lang.Thread.run(Thread.java:841)
     Caused by: android.database.sqlite.SQLiteException: no such column: locationlocation_setting (code 1): , while compiling: SELECT weather._id, date, short_desc, max, min, location_setting, weather_id, coord_lat, coord_long FROM weather INNER JOIN location ON weatherlocation_id = location._id WHERE (locationlocation_setting = ? AND date >= ? ) ORDER BY date ASC
            at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
            at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:889)
            at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:500)
            at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
            at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
            at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:37)
            at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:44)
            at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1314)
            at android.database.sqlite.SQLiteQueryBuilder.query(SQLiteQueryBuilder.java:400)
            at android.database.sqlite.SQLiteQueryBuilder.query(SQLiteQueryBuilder.java:294)
            at com.example.android.sunshine.app.data.WeatherProvider.getWeatherByLocationSetting(WeatherProvider.java:66)
            at com.example.android.sunshine.app.data.WeatherProvider.query(WeatherProvider.java:126)
            at android.content.ContentProvider.query(ContentProvider.java:857)
            at android.content.ContentProvider$Transport.query(ContentProvider.java:200)
            at android.content.ContentResolver.query(ContentResolver.java:461)
            at android.content.ContentResolver.query(ContentResolver.java:404)
            at android.support.v4.content.CursorLoader.loadInBackground(CursorLoader.java:49)
            at android.support.v4.content.CursorLoader.loadInBackground(CursorLoader.java:35)
            at android.support.v4.content.AsyncTaskLoader.onLoadInBackground(AsyncTaskLoader.java:242)
            at android.support.v4.content.AsyncTaskLoader$LoadTask.doInBackground(AsyncTaskLoader.java:51)
            at android.support.v4.content.AsyncTaskLoader$LoadTask.doInBackground(AsyncTaskLoader.java:40)
            at android.support.v4.content.ModernAsyncTask$2.call(ModernAsyncTask.java:123)
            at java.util.concurrent.FutureTask.run(FutureTask.java:237)
            at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
            at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
            at java.lang.Thread.run(Thread.java:841)

1 个答案:

答案 0 :(得分:0)

问题是你的sql查询不正确。 检查你的WeatherProvider类并检查它是什么样的:

    static{
    sWeatherByLocationSettingQueryBuilder = new SQLiteQueryBuilder();
    sWeatherByLocationSettingQueryBuilder.setTables(
            WeatherContract.WeatherEntry.TABLE_NAME + " INNER JOIN " +
            WeatherContract.LocationEntry.TABLE_NAME + 
            " ON " + WeatherContract.WeatherEntry.TABLE_NAME +
            "." + WeatherContract.WeatherEntry.COLUMN_LOC_KEY +
            " = " + WeatherContract.LocationEntry.TABLE_NAME +
            " . " + WeatherContract.LocationEntry._ID);
}

根据您显示的LogCat信息: 引起:android.database.sqlite.SQLiteException:没有这样的列:locationlocation_setting(代码1):,同时编译:

    SELECT weather._id, date, short_desc, max, min, location_setting, weather_id, coord_lat, coord_long FROM weather INNER JOIN location ON weatherlocation_id = location._id WHERE (locationlocation_setting = ? AND date >= ? ) ORDER BY date ASC

但必须是:

    SELECT weather._id, date, short_desc, max, min, location_setting, weather_id, coord_lat, coord_long FROM weather INNER JOIN location ON weather.location_id = location._id WHERE (location.location_setting = ? AND date >= ? ) ORDER BY date ASC          

希望这可以解决问题。 我正在开发相同的应用程序:阳光 现在工作正常。