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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T06:44:41+00:00 2026-06-10T06:44:41+00:00

The program I am having a issue with is a login page that uses

  • 0

The program I am having a issue with is a login page that uses a sqlite db for authentication and a registration page to insert data into the db. I am able to insert data into the db but my login class is not pulling the info from the dn to authenticate plus i receive no errors.

I put a printstackrtace() in my login class but am not sure what the info is actually saying.

db class:

     public class LoginDB extends SQLiteOpenHelper {



//Table attributes
public static final String DATABASE_NAME = "logindatadb";
public static final int DATABASE_VERSION = 1;
public static final String TABLE_NAME_CREDENTIALS = "credentials";

// Data attributes
public static final String COLUMN_NAME_USERNAME = "username";
public static final String COLUMN_NAME_PASSWORD = "passcode";

private static SQLiteOpenHelper DBHelper;
private static SQLiteDatabase db;



public LoginDB(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
        // TODO Auto-generated constructor stub
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        // TODO Auto-generated method stub      

        String sqlDataStore = "create table if not exists " +
        TABLE_NAME_CREDENTIALS + " ("+ BaseColumns._ID + " integer primary key autoincrement,"

                    + COLUMN_NAME_USERNAME + " text not null,"
                    + COLUMN_NAME_PASSWORD + " text not null);";

        db.execSQL(sqlDataStore);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        // TODO Auto-generated method stub
        if(oldVersion == 1 && newVersion == 2){
            //Upgrade the database
    }   

}

    public static boolean Login(String username, String password) {
        Cursor c =  db.rawQuery(
                "SELECT * FROM " + DATABASE_NAME + " WHERE "
                        + COLUMN_NAME_USERNAME + " = '" + username +"' AND "+ COLUMN_NAME_PASSWORD +" = '"+ password +"'" ,  null);
       if (c.getCount()>0)
          return true;
          return false;
    }

    public void open() {
        // TODO Auto-generated method stub
        db = DBHelper.getWritableDatabase();
    }
    public void close() {
        db.close();
    }

}

registration:

    private void insertCredentials(RegDetails regDetails){

        LoginDB androidOpenDBHelper = new LoginDB(this);

        SQLiteDatabase sqliteDB = androidOpenDBHelper.getWritableDatabase();

        ContentValues contentValues = new ContentValues();

        contentValues.put(LoginDB.COLUMN_NAME_USERNAME, rUsername);
        contentValues.put(LoginDB.COLUMN_NAME_PASSWORD, rPasscode);

        long affectedColumnid = sqliteDB.insert(LoginDB.TABLE_NAME_CREDENTIALS, null, contentValues);

        Toast.makeText(getApplicationContext(), "Credentials Saved! Please login" + affectedColumnid, Toast.LENGTH_SHORT).show();

        sqliteDB.close();
        finish();
    }   

  }

Login:

            lsLogin.setOnClickListener (new OnClickListener() {

                @Override
                public void onClick(View v) {
                    //check login
                    String username = lsUsername.getText().toString();
                    String password = lsPassword.getText().toString();
                    try{
                        if(username.length()>0 && password.length()>0)
                        {
                            LoginDB dbUser = new LoginDB(LoginScrExample.this);
                            dbUser.open();

                        if(LoginDB.Login(username, password)) {
                            Intent goToNextActivity = new Intent(getApplicationContext(), menu.class);
                            startActivity(goToNextActivity);

                                Toast.makeText(LoginScrExample.this,"Login Sucessful",Toast.LENGTH_LONG).show();
                            }else{
                                Toast.makeText(LoginScrExample.this,"Invalid Username/Password",Toast.LENGTH_LONG).show();
                            }
                        dbUser.close();
                            }
                    }
                    catch(Exception err){
                        err.printStackTrace();
                        Toast.makeText(LoginScrExample.this," Something is wrong " ,Toast.LENGTH_LONG).show();

                    }

                    }
                       {

                       }    

                                            }
                            );

Logcat when authentication is attempted:

     08-23 14:34:58.713: W/System.err(1396): java.lang.NullPointerException
     08-23 14:34:58.733: W/System.err(1396):    at com.LoginScr.Example.LoginDB.open(LoginDB.java:68)
     08-23 14:34:58.733: W/System.err(1396):    at com.LoginScr.Example.LoginScrExample$1.onClick(LoginScrExample.java:53)
     08-23 14:34:58.733: W/System.err(1396):    at android.view.View.performClick(View.java:3511)
     08-23 14:34:58.733: W/System.err(1396):    at android.view.View$PerformClick.run(View.java:14105)
     08-23 14:34:58.753: W/System.err(1396):    at android.os.Handler.handleCallback(Handler.java:605)
     08-23 14:34:58.753: W/System.err(1396):    at android.os.Handler.dispatchMessage(Handler.java:92)
     08-23 14:34:58.763: W/System.err(1396):    at android.os.Looper.loop(Looper.java:137)
     08-23 14:34:58.775: W/System.err(1396):    at android.app.ActivityThread.main(ActivityThread.java:4424)
     08-23 14:34:58.775: W/System.err(1396):    at java.lang.reflect.Method.invokeNative(Native Method)
     08-23 14:34:58.775: W/System.err(1396):    at java.lang.reflect.Method.invoke(Method.java:511)
     08-23 14:34:58.783: W/System.err(1396):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
     08-23 14:34:58.783: W/System.err(1396):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
     08-23 14:34:58.783: W/System.err(1396):    at dalvik.system.NativeStart.main(Native Method)
     08-23 14:35:20.533: W/IInputConnectionWrapper(1396): showStatusIcon on inactive InputConnection
  • 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-10T06:44:43+00:00Added an answer on June 10, 2026 at 6:44 am
      db = DBHelper.getWritableDatabase();
    

    try changing this to

         db = this.getWritableDatabase();
    

    as your helper class name is not db helper and you have just declared the DBHelper thats why it doesnt show a compilation error

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

Sidebar

Related Questions

I'm having an issue where a client program needs to use a View, but
I've been having an issue with the basic structure of a program that I'm
I'm having an issue with a small program that I wrote. It does what
I am having some issue with understanding of Core Data. In my program there
I'm having an issue with netbeans and Java. My program needs to be able
I am having an issue inserting data from a Java program. My issue is
I'm having an issue in my program in the part that I'm loading a
I'm having an issue with a simple Haskell program. It's supposed to factor a
I'm having a linking issue with a basic C++ program. No, I'm not including
I am having issues with one of my outputs in my program. The issue

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.