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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T21:32:00+00:00 2026-06-18T21:32:00+00:00

I have a big problem when trying to login on my android screen. I

  • 0

I have a big problem when trying to login on my android screen. I have two fields that requires user to enter email and password, it should then go and check sqlite db if correct they will be navigated to mainscreen(login success) if incorrect they will be notified via toast message. My problem is when i hit login button my app displays “Unfortunately stopped working” I cant see any errors in my code! Please someone help!!My code is posted below
*LoginActivity

package com.example.finalproject;


import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class LoginActivity extends Activity implements OnClickListener {


    Button mLogin;
    Button mNewUser;
    Button mShowAll;
    EditText mUsername;
    EditText mPassword;
    SQLiteAdapter mydb = null;
    private String uname;
    private String pass;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);

        mNewUser = (Button)findViewById(R.id.buttonNewUser);
        mNewUser.setOnClickListener(this);

        mLogin = (Button)findViewById(R.id.buttonLogin);
        mLogin.setOnClickListener(this);

        mShowAll = (Button)findViewById(R.id.buttonShowAll);
        mShowAll.setOnClickListener(this);
    }

    public void onClick(View v) {
        SQLiteDatabase db = new SQLiteAdapter(LoginActivity.this).openToWrite();
        if (v.getId() == R.id.buttonLogin) {
            mUsername = (EditText)findViewById(R.id.Username);
            mPassword = (EditText)findViewById(R.id.Password);

            String uname = mUsername.getText().toString();
            String pass = mPassword.getText().toString();

            if(uname.equals("") || uname == null){
                Toast.makeText(getApplicationContext(), "Username Empty", 
                        Toast.LENGTH_SHORT).show();
            }
            else if(pass.equals("") || pass == null){
            Toast.makeText(getApplicationContext(), "Password Empty", 
             Toast.LENGTH_SHORT).show();
            }
            }

        Cursor c = db.rawQuery("SELECT email FROM MY_USERS_TABLE WHERE email= ? AND password=?", new String[] {uname, pass});
        if(c.moveToFirst()) {
            Toast.makeText(getApplicationContext(), "Success", Toast.LENGTH_SHORT).show();
            Intent main = new Intent(LoginActivity.this, MainMenuActivity.class);
            startActivity(main);
        } 
        else {
            Toast.makeText(getApplicationContext(), "Failed..\nTry Again", Toast.LENGTH_SHORT).show();

        }

    }
}

SQLIteAdapter

package com.example.finalproject;

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

public class SQLiteAdapter {

 public static final String MYDATABASE_NAME = "MY_DEVELOPMENT_PROJECT_DATABASE";
 public static final String MYDATABASE_TABLE = "MY_USERS_TABLE";
 public static final int MYDATABASE_VERSION = 1;
 public static final String KEY_ID = "_id";
 public static final String KEY_NAME = "name";
 public static final String KEY_EMAIL = "email";
 public static final String KEY_PASSWORD = "password";


 private static final String SCRIPT_CREATE_DATABASE =
  "create table " + MYDATABASE_TABLE + " ("
  + KEY_ID + " integer primary key autoincrement, "
  + KEY_NAME + " text not null, "
  + KEY_EMAIL + " text not null, "
  + KEY_PASSWORD + " text not null);";

 private SQLiteHelper sqLiteHelper;
 private SQLiteDatabase sqLiteDatabase;

 private Context context;

 public SQLiteAdapter(Context c){
  context = c;
 }

 public SQLiteAdapter(SQLiteAdapter sqLiteAdapter) {
    // TODO Auto-generated constructor stub
}

public SQLiteDatabase openToRead() throws android.database.SQLException {
  sqLiteHelper = new SQLiteHelper(context, MYDATABASE_NAME, null, MYDATABASE_VERSION);
  sqLiteDatabase = sqLiteHelper.getReadableDatabase();
  return sqLiteDatabase; 
 }

 public SQLiteDatabase openToWrite() throws android.database.SQLException {
        sqLiteHelper = new SQLiteHelper(context, MYDATABASE_NAME, null,
                MYDATABASE_VERSION);
        sqLiteDatabase = sqLiteHelper.getWritableDatabase();
        return sqLiteDatabase;
    }
 /*public SQLiteAdapter openToWrite() throws android.database.SQLException {
  sqLiteHelper = new SQLiteHelper(context, MYDATABASE_NAME, null, MYDATABASE_VERSION);
  sqLiteDatabase = sqLiteHelper.getWritableDatabase();
  return this; 
 }*/

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

 public long insert(String name, String email, String password){

  ContentValues contentValues = new ContentValues();
  contentValues.put(KEY_NAME, name);
  contentValues.put(KEY_EMAIL, email);
  contentValues.put(KEY_PASSWORD, password);
  return sqLiteDatabase.insert(MYDATABASE_TABLE, null, contentValues);
 }

 public int deleteAll(){
  return sqLiteDatabase.delete(MYDATABASE_TABLE, null, null);
 }

 public Cursor queueAll(){
  String[] columns = new String[]{KEY_ID, KEY_NAME, KEY_EMAIL,KEY_PASSWORD};
  Cursor cursor = sqLiteDatabase.query(MYDATABASE_TABLE, columns,
    null, null, null, null, null);

  return cursor;
 }

 public class SQLiteHelper extends SQLiteOpenHelper {

  public SQLiteHelper(Context context, String name,
    CursorFactory factory, int version) {
   super(context, name, factory, version);
  }

  @Override
  public void onCreate(SQLiteDatabase db) {
   // TODO Auto-generated method stub
   db.execSQL(SCRIPT_CREATE_DATABASE);
  }

  @Override
  public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
   // TODO Auto-generated method stub
  }
 }




}

RegisteActivty

package com.example.finalproject;






import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.view.View;
//import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import android.widget.TextView;
import android.widget.Toast;

public class RegisterActivity extends Activity {

 EditText inputName, inputEmail, inputPassword;
 Button buttonRegister, buttonDeleteAll;
 TextView login;
 private SQLiteAdapter mySQLiteAdapter;
 ListView listContent;

 SimpleCursorAdapter cursorAdapter;
 Cursor cursor;


   /** Called when the activity is first created. */

@Override
   public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.register_activity);


       inputName = (EditText)findViewById(R.id.name);
       inputEmail = (EditText)findViewById(R.id.email);
       inputPassword = (EditText)findViewById(R.id.password);
       buttonRegister = (Button)findViewById(R.id.register);
       //buttonDeleteAll = (Button)findViewById(R.id.showAll);

       listContent = (ListView)findViewById(R.id.contentlist);

       mySQLiteAdapter = new SQLiteAdapter(this);
       mySQLiteAdapter.openToWrite();

       cursor = mySQLiteAdapter.queueAll();
      // String[] from = new String[]{SQLiteAdapter.KEY_ID, SQLiteAdapter.KEY_NAME, SQLiteAdapter.KEY_EMAIL,SQLiteAdapter.KEY_PASSWORD};
       /*int[] to = new int[]{R.id.id, R.id.text1, R.id.text2,R.id.text3};
       cursorAdapter =
        new SimpleCursorAdapter(this, R.layout.row, cursor, from, to);
       listContent.setAdapter(cursorAdapter);*/

       buttonRegister.setOnClickListener(buttonAddOnClickListener);
       //buttonShowAll.setOnClickListener(buttonShowAllOnClickListener);
       //addListenerOnRegButton();

       TextView loginScreen = (TextView) findViewById(R.id.login);

       // Listening to login 
       loginScreen.setOnClickListener(TextLoginOnClickListener);
}

TextView.OnClickListener TextLoginOnClickListener
= new TextView.OnClickListener(){



@Override
public void onClick(View arg0) {
    Intent i = new Intent(getApplicationContext(), LoginActivity.class);
    startActivity(i);

}
};

   Button.OnClickListener buttonAddOnClickListener
   = new Button.OnClickListener(){



  @Override
  public void onClick(View arg0) {



   String data1 = inputName.getText().toString();
   String data2 = inputEmail.getText().toString();
   String data3 = inputPassword.getText().toString();

   boolean invalid = false;

    if(data1.equals("")){
        invalid = true;
        Toast.makeText(getApplicationContext(), "Name Missing", Toast.LENGTH_SHORT).show();
    }else if(data2.equals("")){
        invalid = true;
        Toast.makeText(getApplicationContext(), "Email ID Missing", Toast.LENGTH_SHORT).show();
    }else if(data3.equals("")){
        invalid = true;
        Toast.makeText(getApplicationContext(), "Password Missing", Toast.LENGTH_SHORT).show();
    }

    if(invalid == false){
        mySQLiteAdapter.insert(data1, data2, data3);
        updateList();
           Toast.makeText(RegisterActivity.this, "You are now registered",
                   Toast.LENGTH_SHORT).show();

        Intent i_register = new Intent(RegisterActivity.this, LoginActivity.class);
        startActivity(i_register);

        inputName.setText("");
        inputEmail.setText("");
        inputPassword.setText("");
        finish();
    }   




  }

   };




  /*Button.OnClickListener buttonShowAllOnClickListener1
   = new Button.OnClickListener(){

  @Override
  public void onClick(View arg0) {
      Intent i = new Intent(RegisterActivity.this, MainMenuActivity.class);
        startActivity(i);
        finish();
  }

   };

 @Override
 protected void onDestroy() {
  // TODO Auto-generated method stub
  super.onDestroy();
  mySQLiteAdapter.close();
 }*/



 private void updateList(){
  //cursor.requery();
   }

}

LogCat

02-04 02:55:56.085: E/AndroidRuntime(17402): FATAL EXCEPTION: main
02-04 02:55:56.085: E/AndroidRuntime(17402): java.lang.IllegalArgumentException: the bind value at index 2 is null
02-04 02:55:56.085: E/AndroidRuntime(17402):    at android.database.sqlite.SQLiteProgram.bindString(SQLiteProgram.java:164)
02-04 02:55:56.085: E/AndroidRuntime(17402):    at android.database.sqlite.SQLiteProgram.bindAllArgsAsStrings(SQLiteProgram.java:200)
02-04 02:55:56.085: E/AndroidRuntime(17402):    at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:47)
02-04 02:55:56.085: E/AndroidRuntime(17402):    at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1314)
02-04 02:55:56.085: E/AndroidRuntime(17402):    at android.database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1253)
02-04 02:55:56.085: E/AndroidRuntime(17402):    at com.example.finalproject.LoginActivity.onClick(LoginActivity.java:62)
02-04 02:55:56.085: E/AndroidRuntime(17402):    at android.view.View.performClick(View.java:4202)
02-04 02:55:56.085: E/AndroidRuntime(17402):    at android.view.View$PerformClick.run(View.java:17340)
02-04 02:55:56.085: E/AndroidRuntime(17402):    at android.os.Handler.handleCallback(Handler.java:725)
02-04 02:55:56.085: E/AndroidRuntime(17402):    at android.os.Handler.dispatchMessage(Handler.java:92)
02-04 02:55:56.085: E/AndroidRuntime(17402):    at android.os.Looper.loop(Looper.java:137)
02-04 02:55:56.085: E/AndroidRuntime(17402):    at android.app.ActivityThread.main(ActivityThread.java:5039)
02-04 02:55:56.085: E/AndroidRuntime(17402):    at java.lang.reflect.Method.invokeNative(Native Method)
02-04 02:55:56.085: E/AndroidRuntime(17402):    at java.lang.reflect.Method.invoke(Method.java:511)
02-04 02:55:56.085: E/AndroidRuntime(17402):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
02-04 02:55:56.085: E/AndroidRuntime(17402):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
02-04 02:55:56.085: E/AndroidRuntime(17402):    at dalvik.system.NativeStart.main(Native Method)
02-04 02:55:56.555: D/dalvikvm(17402): GC_CONCURRENT freed 261K, 11% free 3060K/3436K, paused 126ms+33ms, total 459ms
02-04 03:00:56.444: I/Process(17402): Sending signal. PID: 17402 SIG: 9
  • 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-18T21:32:02+00:00Added an answer on June 18, 2026 at 9:32 pm

    Your problem comes in this line:

    db.rawQuery("SELECT email FROM MY_USERS_TABLE WHERE email= ? AND password=?", new String[] {uname, pass})

    What’s happening is that even if your if statement outputs a Toast to say that the edittexts are empty, this section gets executed, so uname and pass are null, which is giving you the IllegalArgumentException: the bind value at index 2 is null error, as you’re passing the SQL function null values.

    Simple fix: only execute the bottom section of code if the values aren’t null or empty:

    public void onClick(View v) {
        SQLiteDatabase db = new SQLiteAdapter(LoginActivity.this).openToWrite();
        if (v.getId() == R.id.buttonLogin) {
            mUsername = (EditText)findViewById(R.id.Username);
            mPassword = (EditText)findViewById(R.id.Password);
    
            String uname = mUsername.getText().toString();
            String pass = mPassword.getText().toString();
    
            if(uname.equals("") || uname == null){
                Toast.makeText(getApplicationContext(), "Username Empty", 
                Toast.LENGTH_SHORT).show();
            }
            else if(pass.equals("") || pass == null){
    
                Toast.makeText(getApplicationContext(), "Password Empty", 
                Toast.LENGTH_SHORT).show();
    
            } else {
    
                Cursor c = db.rawQuery("SELECT email FROM MY_USERS_TABLE WHERE email= ? AND password=?", new String[] {uname, pass});
                if(c.moveToFirst()) {
                     Toast.makeText(getApplicationContext(), "Success", Toast.LENGTH_SHORT).show();
                     Intent main = new Intent(LoginActivity.this, MainMenuActivity.class);
                     startActivity(main);
                }  else {
                     Toast.makeText(getApplicationContext(), "Failed..\nTry Again", Toast.LENGTH_SHORT).show();
    
                }
           } 
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a weird but big problem. I am trying to let the user
I have big problem when I am trying to deploy my app over clickonce.
I have a big problem that a recursive treeview doesn't update any childs if
I have a big problem that is I have implemented a scheduler in my
I have a big problem. I want to extract text from html table that
I have a (big) problem that all of you that work with Webforms might
I have a Login screen which consists of 2 EditTexts for Username and Password.
Hey Guys I have a big problem that I have no Idea why.. I
Have a problem that seems easy on paper but i'm having a big problem
I have big problem with my keyevent i am trying to call my another

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.