Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7754669
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T12:22:07+00:00 2026-06-01T12:22:07+00:00

This question is famous but everyone always says go to see this Notepad Tutorial

  • 0

This question is famous but everyone always says go to see this Notepad Tutorial.

Which helps, but it doesn’t help that much when you are stuck.

So I have this database that I’ve created on Android and I’d like to display it in a listview, I did the tutorial but I still don’t understand why I cant make it work on my project, so if there is someone who can help, please show yourself!


here is my code

public class MyFridge extends ListActivity {

private DBAdapter db;
public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.notepad_list);
    db = new DBAdapter(this);
    db.open();
    fillData();   


}@Override
public boolean onCreateOptionsMenu (Menu menu)
{


    super.onCreateOptionsMenu(menu);
    CreateMenu(menu);
    return true;
}

@Override
public boolean onOptionsItemSelected (MenuItem item)
{

    switch(item.getItemId())
    {
    case 0:

        Intent f = new Intent(MyFridge.this, Addform.class);
        startActivity(f);

            return true;

    case 1:

        Intent r = new Intent(MyFridge.this, MyRecipes.class);
        startActivity(r);


        return true;

    default:
        return super.onOptionsItemSelected(item);

        }
    }

private void CreateMenu(Menu menu) 
{
    MenuItem mnu1 = menu.add(0, 0, 0, "Add ingredient");
    {
        mnu1.setAlphabeticShortcut('a');//Change the alphabetic shortcut associated with this item.
        mnu1.setIcon(R.drawable.ic_launcher);

    }

    MenuItem mnu2 = menu.add(0, 1, 1, "Delete ingredient");
    {
        mnu2.setAlphabeticShortcut('b');//Change the alphabetic shortcut associated with this item.
        mnu2.setIcon(R.drawable.ic_launcher);
    }
    }

    private void fillData() {
        // Get all of the notes from the database and create the item list
        Cursor c = db.getAllCars();
        startManagingCursor(c);

        String[] from = new String[] { DBAdapter.KEY_TYPE };
        int[] to = new int[] { R.id.text1 };

        // Now create an array adapter and set it to display using our row
        SimpleCursorAdapter notes =
            new SimpleCursorAdapter(this, R.layout.notes_row, c, from, to);
        setListAdapter(notes);
    }

And here is my database:

    public class DBAdapter {
    public static final String KEY_ROWID = "_id";
    public static final String KEY_TYPE = "type";
    public static final String KEY_WEIGHT = "weight";
    public static final String KEY_EXP = "expiration day";

    private static final String TAG = "DBAdapter";

    private static final String DATABASE_NAME = "MyDB";
    private static final String DATABASE_TABLE = "Fridge";
    private static final int DATABASE_VERSION = 2;

    private static final String DATABASE_CREATE =
        "create table Fridge (_id integer primary key autoincrement, "
        + "type text not null, weight integer not null, exp integer not null);";
    //CHECK (P_Id>0)

    private final Context context;    

    private DatabaseHelper DBHelper;
    private SQLiteDatabase db;

    public DBAdapter(Context ctx) 
    {
        this.context = ctx;  
        //It lets newly created objects understand what has been going on.
        //Typically you call it to get information regarding another part of your program
        DBHelper = new DatabaseHelper(context);
    }

    private static class DatabaseHelper extends SQLiteOpenHelper 
    {
        DatabaseHelper(Context context) 
        {
            super(context, DATABASE_NAME, null, DATABASE_VERSION);//calls the context in the parent class
        }

        @Override
        public void onCreate(SQLiteDatabase db) 
        {
            try {
                db.execSQL(DATABASE_CREATE);    
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }

        @Override
        public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) // this method is used if the OS or the version App is changed
        {
            Log.w(TAG, "Upgrading database from version " + oldVersion + " to "
                    + newVersion + ", which will destroy all old data");
            db.execSQL("DROP TABLE IF EXISTS cars");
            onCreate(db);
        }
    }    

    //---opens the database---
    public DBAdapter open() throws SQLException 
    {
        db = DBHelper.getWritableDatabase();
        return this;
    }

    //---closes the database---    
    public void close() 
    {
        DBHelper.close();
    }

    //---insert a contact into the database---
    public long insertCar(String type, int weight, int exp) 
    {
        ContentValues initialValues = new ContentValues();
        initialValues.put(KEY_TYPE, type);
        initialValues.put(KEY_WEIGHT, weight);
        initialValues.put(KEY_EXP, exp);

        return db.insert(DATABASE_TABLE, null, initialValues);
    }

    //---deletes a particular contact---
    public boolean deleteCar(long rowId) 
    {
        return db.delete(DATABASE_TABLE, KEY_ROWID + "=" + rowId, null) > 0;
    }

    //---retrieves all the contacts---
    public Cursor getAllCars() 
    {
        return db.query(DATABASE_TABLE, new String[] {KEY_ROWID, KEY_TYPE,
                KEY_WEIGHT, KEY_EXP}, null, null, null, null, null);
    }

    /*
     * retrieves a particular car
     * 
     */
    public Cursor getCar(String searchString) //throws SQLException 
    {
        Cursor mCursor =
                db.query(true, DATABASE_TABLE, new String[] {KEY_ROWID,
                KEY_TYPE, KEY_WEIGHT,KEY_EXP},KEY_TYPE +"="+"'"+searchString+"'" +" OR "+ KEY_ROWID  + "=" + "'"+searchString +"'"+" OR "+ KEY_EXP + "=" + "'"+searchString +"'"+" OR " + KEY_WEIGHT + "=" + "'" + searchString +"'", null,
                null, null, null, null);

        return mCursor;
    }


    //---updates a contact---
    public boolean updateCar(long rowId, String type, int weight, int exp) 
    {
        ContentValues args = new ContentValues();
        args.put(KEY_TYPE, type);
        args.put(KEY_WEIGHT, weight);
        args.put(KEY_EXP, exp);

        return db.update(DATABASE_TABLE, args, KEY_ROWID + "=" + rowId, null) > 0;
    }
}

Logcat information.

04-09 18:14:47.128: D/TextLayoutCache(23297): Using debug level: 0 - Debug Enabled: 0
04-09 18:14:47.173: D/CLIPBOARD(23297): Hide Clipboard dialog at Starting input: finished by someone else... !
04-09 18:14:49.113: I/SqliteDatabaseCpp(23297): sqlite returned: error code = 1, msg = no such table: Fridge, db=xxx
04-09 18:14:49.113: D/AndroidRuntime(23297): Shutting down VM
04-09 18:14:49.118: W/dalvikvm(23297): threadid=1: thread exiting with uncaught exception (group=0x40c281f8)
04-09 18:14:49.123: E/AndroidRuntime(23297): FATAL EXCEPTION: main
04-09 18:14:49.123: E/AndroidRuntime(23297): java.lang.RuntimeException: Unable to start activity ComponentInfo{wijayaratnam.sutharsun.mobilefridge/wijayaratnam.sutharsun.mobilefridge.MyFridge}: android.database.sqlite.SQLiteException: no such table: Fridge: , while compiling: SELECT _id, type, weight, expiration day FROM Fridge
04-09 18:14:49.123: E/AndroidRuntime(23297):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1968)
04-09 18:14:49.123: E/AndroidRuntime(23297):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1993)
04-09 18:14:49.123: E/AndroidRuntime(23297):    at android.app.ActivityThread.access$600(ActivityThread.java:127)
04-09 18:14:49.123: E/AndroidRuntime(23297):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1159)
04-09 18:14:49.123: E/AndroidRuntime(23297):    at android.os.Handler.dispatchMessage(Handler.java:99)
04-09 18:14:49.123: E/AndroidRuntime(23297):    at android.os.Looper.loop(Looper.java:137)
04-09 18:14:49.123: E/AndroidRuntime(23297):    at android.app.ActivityThread.main(ActivityThread.java:4507)
04-09 18:14:49.123: E/AndroidRuntime(23297):    at java.lang.reflect.Method.invokeNative(Native Method)
04-09 18:14:49.123: E/AndroidRuntime(23297):    at java.lang.reflect.Method.invoke(Method.java:511)
04-09 18:14:49.123: E/AndroidRuntime(23297):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
04-09 18:14:49.123: E/AndroidRuntime(23297):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
04-09 18:14:49.123: E/AndroidRuntime(23297):    at dalvik.system.NativeStart.main(Native Method)
04-09 18:14:49.123: E/AndroidRuntime(23297): Caused by: android.database.sqlite.SQLiteException: no such table: Fridge: , while compiling: SELECT _id, type, weight, expiration day FROM Fridge
04-09 18:14:49.123: E/AndroidRuntime(23297):    at android.database.sqlite.SQLiteCompiledSql.native_compile(Native Method)
04-09 18:14:49.123: E/AndroidRuntime(23297):    at android.database.sqlite.SQLiteCompiledSql.<init>(SQLiteCompiledSql.java:68)
04-09 18:14:49.123: E/AndroidRuntime(23297):    at android.database.sqlite.SQLiteProgram.compileSql(SQLiteProgram.java:143)
04-09 18:14:49.123: E/AndroidRuntime(23297):    at android.database.sqlite.SQLiteProgram.compileAndbindAllArgs(SQLiteProgram.java:361)
04-09 18:14:49.123: E/AndroidRuntime(23297):    at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:127)
04-09 18:14:49.123: E/AndroidRuntime(23297):    at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:94)
04-09 18:14:49.123: E/AndroidRuntime(23297):    at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:53)
04-09 18:14:49.123: E/AndroidRuntime(23297):    at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:47)
04-09 18:14:49.123: E/AndroidRuntime(23297):    at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1690)
04-09 18:14:49.123: E/AndroidRuntime(23297):    at android.database.sqlite.SQLiteDatabase.queryWithFactory(SQLiteDatabase.java:1575)
04-09 18:14:49.123: E/AndroidRuntime(23297):    at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1531)
04-09 18:14:49.123: E/AndroidRuntime(23297):    at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1611)
04-09 18:14:49.123: E/AndroidRuntime(23297):    at wijayaratnam.sutharsun.mobilefridge.DBAdapter.getAllCars(DBAdapter.java:101)
04-09 18:14:49.123: E/AndroidRuntime(23297):    at wijayaratnam.sutharsun.mobilefridge.MyFridge.fillData(MyFridge.java:146)
04-09 18:14:49.123: E/AndroidRuntime(23297):    at wijayaratnam.sutharsun.mobilefridge.MyFridge.onCreate(MyFridge.java:29)
04-09 18:14:49.123: E/AndroidRuntime(23297):    at android.app.Activity.performCreate(Activity.java:4465)
04-09 18:14:49.123: E/AndroidRuntime(23297):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1052)
04-09 18:14:49.123: E/AndroidRuntime(23297):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1932)
04-09 18:14:49.123: E/AndroidRuntime(23297):    ... 11 more
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T12:22:08+00:00Added an answer on June 1, 2026 at 12:22 pm

    If your error is a sql “column not found”, then re-write your create table statement to this:

    private static final String DATABASE_CREATE =
        "create table " + DATABASE_TABLE + " ("
        + KEY_ROWID + " integer primary key autoincrement, "
        + KEY_TYPE + " text not null, "
        + KEY_WEIGHT + " integer not null, "
        + KEY_EXP + " integer not null);";
    

    You’ll notice that you define KEY_EXP = "expiration day" but in your create statement you manually call the column exp; ie column not found. Try to use those variables you create as much as possible to limit these kinds of typos. Good luck!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i know that this is a famous question and have been asked many times.
This question relates to this question which I asked earlier this week. The answer
EDIT 22 March 2011 : This question is no longer that relevant since Youtube
EDIT : I've gotten the famous question badge with this question, so I figured
RoR is famous for being convention over configuration, so it's likely that my question
This question was posted on StackApps , but the issue may be more a
This question seems to have been asked a lot but all were trying to
This question is specific to Erlang, but may have general implications to other IO
This question is a bit different than most. My code works but I don't
This question is similar to this question , bit the big difference is that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.