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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T02:27:31+00:00 2026-06-12T02:27:31+00:00

This is my DataBase Manager Class public class MyDbManager { private String DB_NAME=MyDb; private

  • 0

This is my DataBase Manager Class

public class MyDbManager {

private String DB_NAME="MyDb";
private String TABLE="TableReg";
private int DB_VERSION=1;
//private String ID="id";
private String Fname="Fname";
private String Lname="Lname";
private String Email="Email";
private String Password="Password";
private String Language="Languages";
private String Gender ="gender"; 
private String Id="id";

private SQLiteDatabase sdb;
Context context;
public MyDbManager(Context context) {
    // TODO Auto-generated constructor stub
    this.context=context;
    CustomSQLiteOpenHelper helper= new CustomSQLiteOpenHelper(context);
    this.sdb=helper.getWritableDatabase();      
}

public void insertValues(String fn,String ln, String em, String pwd)
{
    ContentValues values=new ContentValues();
    values.put(Fname, fn);
    values.put(Lname, ln);
    values.put(Email, em);
    values.put(Password, pwd);

// values.put(Language, lang);
// values.put(Gender, gen);

    sdb.insert(TABLE, null, values);
}


public ArrayList<Object> getRow(String email)
{
    // create an array list to store data from the database row.
    // I would recommend creating a JavaBean compliant object 
    // to store this data instead.  That way you can ensure
    // data types are correct.
    ArrayList<Object> rowArray = new ArrayList<Object>();
    Cursor cursor;

    try
    {

        cursor = sdb.query
        (
                TABLE,
                new String[]{Id,Fname,Lname,Email,Password},
                Email + "=" + email,
                null, null, null, null, null
        );

        // move the pointer to position zero in the cursor.
        cursor.moveToFirst();

        // if there is data available after the cursor's pointer, add
        // it to the ArrayList that will be returned by the method.
        if (!cursor.isAfterLast())
        {
            do
            {
                rowArray.add(cursor.getLong(0));
                rowArray.add(cursor.getString(1));
                rowArray.add(cursor.getString(2));
                rowArray.add(cursor.getString(3));
                rowArray.add(cursor.getString(4));

            }
            while (cursor.moveToNext());
        }

        // let java know that you are through with the cursor.
        cursor.close();
    }
    catch (SQLException e) 
    {
        Log.e("DB ERROR", e.toString());
        e.printStackTrace();
    }

    // return the ArrayList containing the given row from the database.
    return rowArray;
}
private class CustomSQLiteOpenHelper extends SQLiteOpenHelper
{
    public CustomSQLiteOpenHelper(Context context)
    {
        super(context,DB_NAME,null,DB_VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase db)
    {

        String newTableQueryString = " create table " + 
                                      TABLE + 
                                      " (" +
                                       Id + " integer primary key autoincrement not null," +
                                      Fname + " text," + 
                                      Lname + " text," + 
                                      Email + " text," + 
                                      Password + " text" +
                                      ");";


        db.execSQL(newTableQueryString);
    }


    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
    {
        //
    }
}

}

The Activity where I tried to retrieve the row:

public class Login extends Activity {

MyDbManager dbm;
EditText ed_em,ed_ps;
Button btn_sgn_in;
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.login);
    dbm=new MyDbManager(this);
    setupviews();
    btn_sgn_in.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            retrieveRow();
        }
    });

}

public void retrieveRow()
{
    String Email=ed_em.getText().toString();
    ArrayList<Object> row;
    row=dbm.getRow(Email);
    String r1=(String)row.get(3);
    Toast.makeText(getBaseContext(), r1, Toast.LENGTH_LONG).show();

}
public void setupviews()
{
    ed_em=(EditText)findViewById(R.id.ed_email_ver);
    ed_ps=(EditText)findViewById(R.id.ed_pass_ver);
    btn_sgn_in=(Button)findViewById(R.id.btn_sgn_in);
}

}

I was trying to retrieve a row from the database and I got the error.. Please help me. I’m new to Android.enter image description here

  • 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-12T02:27:32+00:00Added an answer on June 12, 2026 at 2:27 am

    check the size of arraylist first in If condition

    if(arraylist.size()>3)
    {
         //use arraylist here
    }
    

    and change your method in dbhelper to

    public ArrayList<Object> getRow(String email)
    {
        // create an array list to store data from the database row.
        // I would recommend creating a JavaBean compliant object 
        // to store this data instead.  That way you can ensure
        // data types are correct.
        ArrayList<Object> rowArray = new ArrayList<Object>();
        Cursor cursor;
    
        try
        {
            Cursor cursor = this.db.query(TABLE, new String[] { "Id,Fname,Lname,Email,Password" },
                    "Email =  \"" + email +"\" " , null, null, null,null);
    
            if (cursor.moveToFirst()) {
                 do {
                        rowArray.add(cursor.getLong(0));
                        rowArray.add(cursor.getString(1));
                        rowArray.add(cursor.getString(2));
                        rowArray.add(cursor.getString(3));
                        rowArray.add(cursor.getString(4));              
    
    
                   } while (cursor.moveToNext());
              }
              if (cursor != null && !cursor.isClosed()) {
                 cursor.close();
              }
        }
        catch (SQLException e) 
        {
            Log.e("DB ERROR", e.toString());
            e.printStackTrace();
        }
    
        // return the ArrayList containing the given row from the database.
        return rowArray;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a database manager class where i build a table that has two
I have this class: public class HabitDo{ public int? HabitId { get; set; }
The following function in my Database Manager class is throwing the error: android.os.NetworkOnMainThreadException This
I have a db that is created like this... public class DataBaseManager extends SQLiteOpenHelper{
I have this database structure, SET SQL_MODE=NO_AUTO_VALUE_ON_ZERO; CREATE TABLE IF NOT EXISTS `announces` (
enter code here My problem is this: in this database the junction table contains
public Drawable icon; \\ Some value in this field I am creating a database
To start I have two entities. User.java @Entity public class User { @Id private
During my work on this database application, I've apparently managed to corrupt a form
Let's consider this fabfile def syncdb(): print(green(Database Synchronization ...)) with cd('/var/www/project'): sudo('python manage.py syncdb',

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.