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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T13:12:28+00:00 2026-06-06T13:12:28+00:00

public List<User> getAllUsers() { List<User> userList = new ArrayList<User>(); String selectQuery = SELECT *

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

  String selectQuery = "SELECT  * FROM " + TABLE_USERS;

  SQLiteDatabase db = this.getWritableDatabase();
  Cursor cursor = db.rawQuery(selectQuery, null);

  if (cursor.moveToFirst()) {
   do {
    User user = new User(cursor.getString(0),cursor.getString(1),cursor.getString(2),cursor.getString(3),cursor.getString(4),cursor.getString(5),cursor.getString(6));

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

  return userList;
 }

 public void addUser(User user) {
  SQLiteDatabase db = this.getWritableDatabase();

  ContentValues values = new ContentValues();
  values.put(KEY_ID, user._id); // User id
  values.put(KEY_BLUETOOTH_NAME, user._bluetooth_name);
  values.put(KEY_COLOR, user._color);
  values.put(KEY_LAST_LAT, user._last_lat);
  values.put(KEY_LAST_LNG, user._last_lng);
  values.put(KEY_MODEL, user._model);
  values.put(KEY_LAST_SEEN, user._last_seen);

  db.insert(TABLE_USERS, null, values);
  db.close(); 
 }

User class properties

public class User {

String _id;
String _bluetooth_name;
String _color;
String _last_seen;
String _model;
String _last_lng;
String _last_lat;

 public User(String id, String bluetooth_name, String color, String last_seen, String model, String last_lng, String last_lat){
      this._id = id;
      this._bluetooth_name = bluetooth_name;
      this._color = color;
      this._last_seen = last_seen;
      this._model = model;
      this._last_lat = last_lat;
      this._last_lng = last_lng;
 }

}

DatabaseHandler dh = new DatabaseHandler(getApplicationContext());

dh.clearTable(); //clear the table

User user = new User("1","2","3","5","6","7","8"); //add dummy user

dh.addUser(user);

List<User> userlist = dh.getAllUsers(); //all users properties are null, except "id" (which is the first prop, value: "1")

Probably an easy question since this is my first attempt at using SQLite in android:

I’m trying to get all the users that I’ve added to my users SQLite table. But only the first property, “id”, on all my users are set. Can anyone please explain why?

Update:

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

 @Override
 public void onCreate(SQLiteDatabase db) {
  String CREATE_USERS_TABLE = "CREATE TABLE " + TABLE_USERS + "(" +
     KEY_ID + " INTEGER PRIMARY KEY," +
     KEY_BLUETOOTH_NAME + " TEXT," +
     KEY_COLOR + " TEXT," +
     KEY_LAST_LAT + " TEXT," +
     KEY_LAST_LNG + " TEXT," +
     KEY_LAST_SEEN + " TEXT," +
     KEY_MODEL + " TEXT" + ")";

  db.execSQL(CREATE_USERS_TABLE);
 }
  • 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-06T13:12:29+00:00Added an answer on June 6, 2026 at 1:12 pm

    I can imagine such a scenario: you’re developing the DB scheme and at some version the table has only _id column. You run the app, so it creates the DB/table. Then you add all the rest of the columns to the table creation code, but since the table has already been created the code is not executed again, so the table remains unchanged. If this theory is true, then reinstalling the app should fix it.

    UPDATE:

    I hope KEY_ID is “_id”? If not, please fix. Also the SQL for KEY_ID should be:

    KEY_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
    

    UPDATE2:

    Sorry, my UPDATE section above messed up DB id with your business logic User id. So I’d suggest to use KEY_UID (“uid”) for business logic User id and KEY_DB_ID (“_id”) for DB id.

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

Sidebar

Related Questions

I've got a public List<FriendProfile> friends = new ArrayList<FriendProfile>(); . I initialize the friends
what is wrong with such code public List<SearchItem> Search(string find) { return (from i
i am using icefaces select on menu to select a user from list of
In my experience I call simple web methods, like this: [WebMethod] public List<string> GetUserListByLetters(string
[WebMethod] public List< string> HelloWorld(string prefixText) { SqlConnection con = new SqlConnection(Database=bluedd;Server=(local);Integrated Security=SSPI); con.Open();
class Foo(){ public List<string> SomeCollection; } I need to implement an event which can
The original code: public List<Contact> GetContactListEntityCompiledLINQ() { if (entities == null) entities = new
when using this method public List<Field> getFieldWithoutId(List<Integer> idSections) throws Exception { try { Connection
I have the this function: @Override public List<Expense> getExpensesBetween(Date firstDate, Date secondDate) { Query
Until now I selected Entities like this: public List<Customer> findAll() { TypedQuery<Customer> query =

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.