Ehsan Hasannia
Ehsan Hasannia

Reputation: 101

android.database.sqlite.SQLiteException: near ")": syntax error (code 1)

i check every thing many times but still i got this message

android.database.sqlite.SQLiteException: near ")": syntax error (code 1): , while compiling: CREATE TABLE location (_id INTEGER PRIMARY KEY AUTOINCREMENT, location_setting TEXT UNIQUE NOT NULL, city_name TEXT NOT NULL, coord_lat REAL NOT NULL, coord_long REAL NOT NULL,  );

final String SQL_CREATE_WEATHER_TABLE = "CREATE TABLE " + WeatherContract.WeatherEntry.TABLE_NAME + " (" +

            WeatherContract.WeatherEntry._ID + " INTEGER PRIMARY KEY AUTOINCREMENT," +

            // the ID of the location entry associated with this weather data
            WeatherContract.WeatherEntry.COLUMN_LOC_KEY + " INTEGER NOT NULL, " +
            WeatherContract.WeatherEntry.COLUMN_DATE + " INTEGER NOT NULL, " +
            WeatherContract.WeatherEntry.COLUMN_SHORT_DESC + " TEXT NOT NULL, " +
            WeatherContract.WeatherEntry.COLUMN_WEATHER_ID + " INTEGER NOT NULL," +

            WeatherContract.WeatherEntry.COLUMN_MIN_TEMP + " REAL NOT NULL, " +
            WeatherContract.WeatherEntry.COLUMN_MAX_TEMP + " REAL NOT NULL, " +

            WeatherContract.WeatherEntry.COLUMN_HUMIDITY + " REAL NOT NULL, " +
            WeatherContract.WeatherEntry.COLUMN_PRESSURE + " REAL NOT NULL, " +
            WeatherContract.WeatherEntry.COLUMN_WIND_SPEED + " REAL NOT NULL, " +
            WeatherContract.WeatherEntry.COLUMN_DEGREES + " REAL NOT NULL, " +

            // Set up the location column as a foreign key to location table.
            " FOREIGN KEY (" + WeatherContract.WeatherEntry.COLUMN_LOC_KEY + ") REFERENCES " +
            WeatherContract.LocationEntry.TABLE_NAME + " (" + WeatherContract.LocationEntry._ID + "), " +

            // To assure the application have just one weather entry per day
            // per location, it's created a UNIQUE constraint with REPLACE strategy
            " UNIQUE (" + WeatherContract.WeatherEntry.COLUMN_DATE + ", " +
            WeatherContract.WeatherEntry.COLUMN_LOC_KEY + ") ON CONFLICT REPLACE );";

    final String SQL_CREATE_LOCATION_TABLE = "CREATE TABLE "+ WeatherContract.LocationEntry.TABLE_NAME +" (" +
            WeatherContract.LocationEntry._ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "+
            WeatherContract.LocationEntry.COLUMN_LOCATION_SETTING +" TEXT UNIQUE NOT NULL, "+
            WeatherContract.LocationEntry.COLUMN_CITY_NAME + " TEXT NOT NULL, "+
            WeatherContract.LocationEntry.COLUMN_COORD_LAT + " REAL NOT NULL, "+
            WeatherContract.LocationEntry.COLUMN_COORD_LONG+ " REAL NOT NULL, "+" );";


    sqLiteDatabase.execSQL(SQL_CREATE_LOCATION_TABLE);


    sqLiteDatabase.execSQL(SQL_CREATE_WEATHER_TABLE);

Upvotes: 1

Views: 1116

Answers (2)

Dhaval Parmar
Dhaval Parmar

Reputation: 18978

its showing message of syntext error in create table query. Because you have added extra ,(coma) in last field of table. so,remove ,(coma) from SQL_CREATE_LOCATION_TABLE just like below & try again


final String SQL_CREATE_LOCATION_TABLE = "CREATE TABLE "+ WeatherContract.LocationEntry.TABLE_NAME +" (" +
            WeatherContract.LocationEntry._ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "+
            WeatherContract.LocationEntry.COLUMN_LOCATION_SETTING +" TEXT UNIQUE NOT NULL, "+
            WeatherContract.LocationEntry.COLUMN_CITY_NAME + " TEXT NOT NULL, "+
            WeatherContract.LocationEntry.COLUMN_COORD_LAT + " REAL NOT NULL, "+
            WeatherContract.LocationEntry.COLUMN_COORD_LONG+ " REAL NOT NULL "+" );";

Upvotes: 0

Ravi
Ravi

Reputation: 35549

Its typo, check your last line

WeatherContract.LocationEntry.COLUMN_COORD_LONG+ " REAL NOT NULL, "+" );";

remove , from end after NOT NULL, it should be like

WeatherContract.LocationEntry.COLUMN_COORD_LONG+ " REAL NOT NULL "+" );";

Upvotes: 1

Related Questions