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 8910217
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T03:37:55+00:00 2026-06-15T03:37:55+00:00

I am having trouble executing my SQLite app on adroid. For testing purpose I

  • 0

I am having trouble executing my SQLite app on adroid. For testing purpose I made it as simple as possible. A query that adds data into the database, and when the user clicks on “View Schedule” button, all the data in the DB should be displayed as a TOAST message.
“The MySQLitehelper.java” file has all the Database related code and the “SelectOptions.java” has the code that has the button to “View Schedule”. All the right imports have been added hence I have omitted them here.

On Tracing LogCat, I see that there is a null pointer exception when you call the helper.open() method of MySQLitehelper class. I tried printing statements to track it and figured out that the program shuts down the following lines:

  public MySQLitehelper open() throws SQLException
 {
    System.out.println("Inside open function");
     db = dbhelper.getReadableDatabase();  // even tried helper.getWritableDatabase()
    return this;
 }

and stops when the line

 db = dbhelper.getReadableDatabase(); 

is encountered.
Here is my code:

/* ————–MySQLitehelper.java code —————–*/

public class MySQLitehelper {

//public static final String TABLE_COMMENTS = "comments";
  public static final String COLUMN_ID = "GWid";
  public static final String COLUMN_DATE = "date";
  public static final String COLUMN_LOCATION = "location";
  public static final String COLUMN_TIME = "time";

  public static final String TABLE_NAME = "UPDTable";

  private static final String DATABASE_NAME = "UPDdb";
  private static final int DATABASE_VERSION = 1;

  private final Context context;


  // Database creation sql statement
  private static final String DATABASE_CREATE = "CREATE TABLE IF NOT EXISTS " + TABLE_NAME +
                                " (" +COLUMN_ID+ " VARCHAR," + COLUMN_DATE + "VARCHAR," +
                                COLUMN_LOCATION+" VARCHAR," +COLUMN_TIME +" VARCHAR);";

  private static final String DATABASE_INSERT = "INSERT INTO " +TABLE_NAME +
                                                " Values ('47688507','DEC-07-2012','MARVIN 203','20:00');";


  DatabaseHelper dbhelper;
  SQLiteDatabase db;

 public MySQLitehelper(Context ctx)
  {
      this.context = ctx;
  }

 private static class DatabaseHelper extends SQLiteOpenHelper {

     public DatabaseHelper(Context context)
     {
         super(context,DATABASE_NAME, null,DATABASE_VERSION);
     }

 @Override
public void onCreate(SQLiteDatabase db) {
    // TODO Auto-generated method stub
    db.execSQL(DATABASE_CREATE);            //execute create table
    db.execSQL(DATABASE_INSERT);            //execute insert query

}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    // TODO Auto-generated method stub
    Log.w(MySQLitehelper.class.getName(),
            "Upgrading database from version " + oldVersion + " to "
                + newVersion + ", which will destroy all old data");
        db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
        onCreate(db);
    }
}


// open the DB
 public MySQLitehelper open() throws SQLException
 {
    System.out.println("Inside open function");
     db = dbhelper.getReadableDatabase();
    return this;
 }

 public void close()
 {
     dbhelper.close();
 }


public Cursor getAllrows()      //function to get all rows in the DB. Testing initially.
{
    //SQLiteDatabase db=this.getReadableDatabase();
    Cursor cur=db.query(TABLE_NAME,new String []{COLUMN_ID, COLUMN_DATE,
            COLUMN_LOCATION,COLUMN_TIME},null,null,null,null, null);

     return cur;
}

  }

/————- SelectOptions.java class ——————/

    public class SelectOptions extends Activity {

Button btnView, btnDrop, btnLocation;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_select_options);


    Intent intent = getIntent();
    String message = intent.getStringExtra(MainActivity.EXTRA_MESSAGE);

    btnView = (Button)findViewById(R.id.btnViewShift);
    btnDrop = (Button)findViewById(R.id.btnDropShift);
    btnLocation = (Button)findViewById(R.id.btnViewLocation);


    final MySQLitehelper helper = new MySQLitehelper(this);


    btnView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View arg0) {

            helper.open();
            Cursor c = helper.getAllrows();
              if (c.moveToFirst()) {
             do {

                 System.out.println("In Do while");
                 DisplayRecord(c); 

             } while (c.moveToNext());
          }
            helper.close(); 
            System.out.println("Out of Do");



        }  
    });


}

public void DisplayRecord(Cursor c)
{
    System.out.println("In side toast display function");
    Toast.makeText(this, "id: "+c.getString(0)+"\n"+
            "Date: "+c.getString(1)+"\n"+
            "Location: "+c.getString(2)+"\n"+
            "Time: "+c.getString(3), Toast.LENGTH_LONG).show();
}


    }

LogCat

11-29 06:18:01.393: I/System.out(8162): Inside open function
11-29 06:18:01.453: E/SQLiteLog(8162): (1) no such column: date
11-29 06:18:01.453: D/AndroidRuntime(8162): Shutting down VM
11-29 06:18:01.463: W/dalvikvm(8162): threadid=1: thread exiting with uncaught exception (group=0x40a70930)
11-29 06:18:01.503: E/AndroidRuntime(8162): FATAL EXCEPTION: main
11-29 06:18:01.503: E/AndroidRuntime(8162): android.database.sqlite.SQLiteException: no such column: date (code 1): , while compiling: SELECT GWid, date, location, time FROM UPDTable
11-29 06:18:01.503: E/AndroidRuntime(8162):     at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
11-29 06:18:01.503: E/AndroidRuntime(8162):     at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:882)
11-29 06:18:01.503: E/AndroidRuntime(8162):     at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:493)
11-29 06:18:01.503: E/AndroidRuntime(8162):     at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
11-29 06:18:01.503: E/AndroidRuntime(8162):     at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
11-29 06:18:01.503: E/AndroidRuntime(8162):     at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:37)
11-29 06:18:01.503: E/AndroidRuntime(8162):     at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:44)
  • 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-15T03:37:56+00:00Added an answer on June 15, 2026 at 3:37 am

    There is a syntax error in the line below . The format of the 20:00 parameter is invalid. Should be a string “20:00” or valid integer or float – 20.0

     enter code here`private static final String DATABASE_INSERT = "INSERT INTO " +
          TABLE_NAME +    " Values ('47688507','DEC-07-2012','MARVIN 203',20:00);";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We are having trouble executing scripts that begin with BEGIN and are having multiple
I'm having some trouble executing a nested sql query. It works fine when i
I'm having trouble executing a stored proc... I've got C# code that tries to
I'm having trouble executing a Doctrine DQL Query. This is the error it gives
I am having trouble optimizing a relatively simple query involving a GROUP BY, ORDER
I'm having trouble executing an UPDATE-query with fmdb. It locks the application without any
Using Advantage Database Server 8.1 I am having trouble executing a successful query. I
I'm having some trouble executing a dynamic query inside my SP, and I thought
Having trouble framing this assertion in Rspec for my rails app. A User has
Having trouble with proper regex for RewriteCond RewriteCond %{REQUEST_URI} !^/foo/ Works as expected, 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.