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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T07:38:46+00:00 2026-06-01T07:38:46+00:00

LogIn class where my database is used: package edu.flying.panda.taskmanager; import android.util.Log; import android.view.View; import

  • 0

LogIn class where my database is used:

package edu.flying.panda.taskmanager;


import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;

/**
 * Login Screen
 * @author FlyingPanda
 */

public class LogIn extends Activity {

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.log_in);

    final DatabaseHandler userDB = new DatabaseHandler(this);

    final Button logIn_button = (Button) findViewById(R.id.log_in_logIn_button);
    final Button signUp_button = (Button) findViewById(R.id.log_in_register_button);

    /**
     * Listener for LogIn button, checks for correct Username/Password and handles errors
     */
    logIn_button.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {

            EditText username = (EditText) findViewById(R.id.log_in_username);
            EditText password = (EditText) findViewById(R.id.log_in_pass);
            TextView errorText = (TextView) findViewById(R.id.log_in_error);


            //check credentials

            User user = userDB.getUser(username.getText().toString());
            //error^
            Log.d("cc", "user is found");
            if (user!=null){
                Log.d("cc", "user is not null");
                if (user.getPassword().equals(password)){
                    Log.d("cc", "pass correct");

                }else {
                    errorText.setText("Username/Password incorrect");
                }
            }
        }
    });



}

My databaseHelper class, which uses SQLite

package edu.flying.panda.taskmanager;

import java.util.ArrayList;
import java.util.List;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class DatabaseHandler extends SQLiteOpenHelper{

    //db version
    private static final int DATABASE_VERSION = 1;
    //db name
    private static final String DATABASE_NAME = "userManager";
    //table name
    private static final String TABLE_USERS = "users";
    //user table column names
    private static final String KEY_ID = "id";
    private static final String KEY_USERNAME = "username";
    private static final String KEY_PASSWORD = "password";
    private static final String KEY_NAME = "name";
    private static final String KEY_EMAIL = "email";
    //constructor
    public DatabaseHandler(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
    }       
    // Creating Tables
    @Override
    public void onCreate(SQLiteDatabase db) {
        String CREATE_USERS_TABLE = "CREATE TABLE" + TABLE_USERS + "(" + KEY_ID + 
                "INTEGER PRIMARY KEY," + KEY_USERNAME + "TEXT," + KEY_PASSWORD + "TEXT,"
                + KEY_NAME + "TEXT," + KEY_EMAIL + "TEXT" + ")";

        db.execSQL(CREATE_USERS_TABLE);
    }
    // Upgrading database
    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        // Drop older table if existed
        db.execSQL("DROP TABLE IF EXISTS " + TABLE_USERS);

        // Create tables again
        onCreate(db);
    }
    public void addUser(User user){
        SQLiteDatabase db = this.getWritableDatabase();

        ContentValues values = new ContentValues();
        values.put(KEY_USERNAME, user.getUsername());
        values.put(KEY_PASSWORD, user.getPassword());
        values.put(KEY_NAME, user.getName());
        values.put(KEY_EMAIL, user.getEmail());

        //inserting row
        db.insert(TABLE_USERS, null, values);
        db.close();
    }
    //get user by id
    public User getUser(int id){
        SQLiteDatabase db = this.getReadableDatabase();

        //cursor returned will only be one row of the table, with the matching id
        Cursor cursor = db.query(TABLE_USERS, 
                new String[]{KEY_ID, KEY_USERNAME, KEY_PASSWORD, KEY_NAME, KEY_EMAIL},
                KEY_ID + "=?", new String[]{String.valueOf(id)}, null, null, null, null);

        if (cursor !=null) cursor.moveToFirst();

        User user = new User(Integer.parseInt(cursor.getString(0)),cursor.getString(1),cursor.getString(2),cursor.getString(3), cursor.getString(4));

        return user;

    }
    public  User getUser(String username){
        SQLiteDatabase db = this.getReadableDatabase();

        //cursor returned will only be one row of the table, with the matching id
        Cursor cursor = db.query(TABLE_USERS, 
                new String[]{KEY_ID, KEY_USERNAME , KEY_PASSWORD, KEY_NAME, KEY_EMAIL},
                KEY_USERNAME + "=?", new String[]{username}, null, null, null, null);

        if (cursor !=null) cursor.moveToFirst();

        User user = new User(Integer.parseInt(cursor.getString(0)),cursor.getString(1),cursor.getString(2),cursor.getString(3), cursor.getString(4));

        return user;

    }
    public List<User> getAllUsers(){
        List<User> userList = new ArrayList<User>();

        //select all query
        String selectQuery = "SELECT * FROM " + TABLE_USERS;

        SQLiteDatabase db = this.getReadableDatabase();
        //just a cursor that points to the user table TABLE_USERS
        Cursor cursor = db.rawQuery(selectQuery, null);

        //adding users to list
        if(cursor.moveToFirst()){
            do{
                User user = new User();
                user.setId(Integer.parseInt(cursor.getString(0)));
                user.setUsername(cursor.getString(1));
                user.setPassword(cursor.getString(2));
                user.setName(cursor.getString(3));
                user.setEmail(cursor.getString(4));

                userList.add(user);
            }while(cursor.moveToNext());
        }

        return userList;
    }

Logcat:

03-31 22:26:33.613: I/SqliteDatabaseCpp(538): sqlite returned: error code = 1, msg = near "TABLEusers": syntax error, db=/data/data/edu.flying.panda.taskmanager/databases/userManager
03-31 22:26:33.653: E/SQLiteOpenHelper(538): Couldn't open userManager for writing (will try read-only):
03-31 22:26:33.653: E/SQLiteOpenHelper(538): android.database.sqlite.SQLiteException: near "TABLEusers": syntax error: , while compiling: CREATE TABLEusers(idINTEGER PRIMARY KEY,usernameTEXT,passwordTEXT,nameTEXT,emailTEXT)
03-31 22:26:33.653: E/SQLiteOpenHelper(538):    at android.database.sqlite.SQLiteCompiledSql.native_compile(Native Method)
03-31 22:26:33.653: E/SQLiteOpenHelper(538):    at android.database.sqlite.SQLiteCompiledSql.<init>(SQLiteCompiledSql.java:68)
03-31 22:26:33.653: E/SQLiteOpenHelper(538):    at android.database.sqlite.SQLiteProgram.compileSql(SQLiteProgram.java:134)
03-31 22:26:33.653: E/SQLiteOpenHelper(538):    at android.database.sqlite.SQLiteProgram.compileAndbindAllArgs(SQLiteProgram.java:361)
03-31 22:26:33.653: E/SQLiteOpenHelper(538):    at android.database.sqlite.SQLiteStatement.acquireAndLock(SQLiteStatement.java:260)
03-31 22:26:33.653: E/SQLiteOpenHelper(538):    at android.database.sqlite.SQLiteStatement.executeUpdateDelete(SQLiteStatement.java:84)
03-31 22:26:33.653: E/SQLiteOpenHelper(538):    at android.database.sqlite.SQLiteDatabase.executeSql(SQLiteDatabase.java:1899)
03-31 22:26:33.653: E/SQLiteOpenHelper(538):    at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1839)
03-31 22:26:33.653: E/SQLiteOpenHelper(538):    at edu.flying.panda.taskmanager.DatabaseHandler.onCreate(DatabaseHandler.java:37)
03-31 22:26:33.653: E/SQLiteOpenHelper(538):    at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:165)
03-31 22:26:33.653: E/SQLiteOpenHelper(538):    at android.database.sqlite.SQLiteOpenHelper.getReadableDatabase(SQLiteOpenHelper.java:231)
03-31 22:26:33.653: E/SQLiteOpenHelper(538):    at edu.flying.panda.taskmanager.DatabaseHandler.getUser(DatabaseHandler.java:78)
03-31 22:26:33.653: E/SQLiteOpenHelper(538):    at edu.flying.panda.taskmanager.LogIn$1.onClick(LogIn.java:55)
03-31 22:26:33.653: E/SQLiteOpenHelper(538):    at android.view.View.performClick(View.java:3511)
03-31 22:26:33.653: E/SQLiteOpenHelper(538):    at android.view.View$PerformClick.run(View.java:14105)
03-31 22:26:33.653: E/SQLiteOpenHelper(538):    at android.os.Handler.handleCallback(Handler.java:605)
03-31 22:26:33.653: E/SQLiteOpenHelper(538):    at android.os.Handler.dispatchMessage(Handler.java:92)
03-31 22:26:33.653: E/SQLiteOpenHelper(538):    at android.os.Looper.loop(Looper.java:137)
03-31 22:26:33.653: E/SQLiteOpenHelper(538):    at android.app.ActivityThread.main(ActivityThread.java:4424)
03-31 22:26:33.653: E/SQLiteOpenHelper(538):    at java.lang.reflect.Method.invokeNative(Native Method)
03-31 22:26:33.653: E/SQLiteOpenHelper(538):    at java.lang.reflect.Method.invoke(Method.java:511)
03-31 22:26:33.653: E/SQLiteOpenHelper(538):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
03-31 22:26:33.653: E/SQLiteOpenHelper(538):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
03-31 22:26:33.653: E/SQLiteOpenHelper(538):    at dalvik.system.NativeStart.main(Native Method)
03-31 22:26:33.683: D/AndroidRuntime(538): Shutting down VM
03-31 22:26:33.683: W/dalvikvm(538): threadid=1: thread exiting with uncaught exception (group=0x409c01f8)
03-31 22:26:33.713: E/AndroidRuntime(538): FATAL EXCEPTION: main
03-31 22:26:33.713: E/AndroidRuntime(538): android.database.sqlite.SQLiteException: Can't upgrade read-only database from version 0 to 1: /data/data/edu.flying.panda.taskmanager/databases/userManager
03-31 22:26:33.713: E/AndroidRuntime(538):  at android.database.sqlite.SQLiteOpenHelper.getReadableDatabase(SQLiteOpenHelper.java:244)
03-31 22:26:33.713: E/AndroidRuntime(538):  at edu.flying.panda.taskmanager.DatabaseHandler.getUser(DatabaseHandler.java:78)
03-31 22:26:33.713: E/AndroidRuntime(538):  at edu.flying.panda.taskmanager.LogIn$1.onClick(LogIn.java:55)
03-31 22:26:33.713: E/AndroidRuntime(538):  at android.view.View.performClick(View.java:3511)
03-31 22:26:33.713: E/AndroidRuntime(538):  at android.view.View$PerformClick.run(View.java:14105)
03-31 22:26:33.713: E/AndroidRuntime(538):  at android.os.Handler.handleCallback(Handler.java:605)
03-31 22:26:33.713: E/AndroidRuntime(538):  at android.os.Handler.dispatchMessage(Handler.java:92)
03-31 22:26:33.713: E/AndroidRuntime(538):  at android.os.Looper.loop(Looper.java:137)
03-31 22:26:33.713: E/AndroidRuntime(538):  at android.app.ActivityThread.main(ActivityThread.java:4424)
03-31 22:26:33.713: E/AndroidRuntime(538):  at java.lang.reflect.Method.invokeNative(Native Method)
03-31 22:26:33.713: E/AndroidRuntime(538):  at java.lang.reflect.Method.invoke(Method.java:511)
03-31 22:26:33.713: E/AndroidRuntime(538):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
03-31 22:26:33.713: E/AndroidRuntime(538):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
03-31 22:26:33.713: E/AndroidRuntime(538):  at dalvik.system.NativeStart.main(Native Method)

I used Logcat to check how far the program got before it reached the error.
I have commented //error^ under the line of code where it fails.

that line of code is: User user = userDB.getUser(username.getText().toString());

I’m fairly new to SQLite, so this syntax error really throws me off.

I’m thinking the problem is in how I created my table. But I don’t know.
Thanks for any help.

  • 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-01T07:38:47+00:00Added an answer on June 1, 2026 at 7:38 am

    You need to include appropriate spacing in your create table query:

    String CREATE_USERS_TABLE = "CREATE TABLE " + TABLE_USERS + "(" + KEY_ID + 
    " INTEGER PRIMARY KEY," + KEY_USERNAME + " TEXT," + KEY_PASSWORD + " TEXT,"
    + KEY_NAME + " TEXT," + KEY_EMAIL + " TEXT" + ");";
    

    For better usage, its is good to use String.format:

    String query = String.format("CREATE TABLE %s (%s INTEGER PRIMARY KEY,
    %s TEXT, %s TEXT, %s TEXT, %s TEXT);", TABLE_USERS, KEY_ID, KEY_USERNAME,
    KEY_PASSWORD, KEY_NAME, KEY_EMAIL);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a static class that contains my database logic. This class is used
I have a class library with all my database logic. My DAL/BLL. I have
I have a Login Class which has a function: isCorrect() that takes username and
I'm looking for a good PHP login class via MySQL, and I'm not yet
Im making a login/logout class that logs users in, sets cookies based on user's
I've built a class called Login with a construct that either logs them in
i saw a example for login form same blow code class Form_Login extends Zend_Form
Hi every one I have these classe @Entity @Table(name = login, uniqueConstraints={@UniqueConstraint(columnNames={username_fk})}) public class
I have an exisiting database which I used to create a Model usign the
I'm building an android app which has a login and logout option. How do

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.