mercredi 2 décembre 2015

Error Opening Database

I am having some trouble calling to one of my android databases. I am trying to read form my database and put the values into a listview. However I am getting an error saying the table doesnt exist. I have looked around at other people who have had the same error but I cant see why mine is different. I have re written the creates, double checked the spelling but still cant figure out where I have gone wrong

Error

Caused by: android.database.sqlite.SQLiteException: no such table: recipes (code 1): , while compiling: SELECT reciep_name FROM recipes
12-02 12:16:17.191 28118-28118/? E/AndroidRuntime:     at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
12-02 12:16:17.191 28118-28118/? E/AndroidRuntime:     at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:887)
12-02 12:16:17.191 28118-28118/? E/AndroidRuntime:     at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:498)
12-02 12:16:17.191 28118-28118/? E/AndroidRuntime:     at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
12-02 12:16:17.191 28118-28118/? E/AndroidRuntime:     at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
12-02 12:16:17.191 28118-28118/? E/AndroidRuntime:     at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:37)
12-02 12:16:17.191 28118-28118/? E/AndroidRuntime:     at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:44)
12-02 12:16:17.191 28118-28118/? E/AndroidRuntime:     at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1316)
12-02 12:16:17.191 28118-28118/? E/AndroidRuntime:     at android.database.sqlite.SQLiteDatabase.queryWithFactory(SQLiteDatabase.java:1163)
12-02 12:16:17.191 28118-28118/? E/AndroidRuntime:     at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1034)
12-02 12:16:17.191 28118-28118/? E/AndroidRuntime:     at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1202)
12-02 12:16:17.191 28118-28118/? E/AndroidRuntime:     at com.example.rory.prototypev2.DBAdapter.getAllRecipes(DBAdapter.java:107)
12-02 12:16:17.191 28118-28118/? E/AndroidRuntime:     at com.example.rory.prototypev2.showRecipes.onCreate(showRecipes.java:29)

showRecipe

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_show_recipes);
        // toolbar = (Toolbar) findViewById(R.id.toolbar);
        //setSupportActionBar(toolbar);

        DBAdapter db = new DBAdapter(this);
        db.open();

        Cursor cursor = db.getAllRecipes();  //Error here

        String[] columns = new String[] {db.KEY_RECIPE_NAME};
        int[] to = new int[] {R.id.recipeName};

        SimpleCursorAdapter myCursorAdapter = new SimpleCursorAdapter(this,R.layout.row1, cursor, columns, to, 0);

        ListView recipeList = (ListView) findViewById(R.id.receipList);
        recipeList.setAdapter(myCursorAdapter);

getAllRecipes Where Error is

//--Get All Recipes --//
public Cursor getAllRecipes()
{
    return db.query(DATABASE_TABLE_RECIPES, new String[]{KEY_RECIPE_NAME}, null, null, null, null, null);
}

Create

public static final String KEY_RECIPE_CODE="recipe_code";
public static final String KEY_RECIPE_NAME="reciep_name";
private static final String CREATE_TABLE_RECIPES = "create table if not exists recipes (_id INTEGER AUTOINCREMENT, recipe_code INTERGER PRIMARY KEY AUTOINCREMENT, recipe_name TEXT)" ;

Aucun commentaire:

Enregistrer un commentaire