SQL Android Null Reports

80 views Asked by At

So I've been working for what feels like endless hours trying to get a social network between my friends and I, possibly more when I get better at programming. I have successfully made a database that allows users to create an account, and even add friends, but I can't seem to display the friends? I can display any information from the user account, but not the friends? To see things on an account, i query it with

    public HashMap<String, String> getUserDetails(){
    HashMap<String,String> user = new HashMap<String,String>();
    String selectQuery = "SELECT  * FROM " + TABLE_LOGIN;

    SQLiteDatabase db = this.getReadableDatabase();
    Cursor cursor = db.rawQuery(selectQuery, null);
    // Move to first row
    cursor.moveToFirst();
    if(cursor.getCount() > 0){
        user.put("name", cursor.getString(1));
        user.put("email", cursor.getString(2));
        user.put("uid", cursor.getString(3));
        user.put("created_at", cursor.getString(4));
    }
    cursor.close();
    db.close();
    // return user
    return user;
}

And then in the activity, I call this with

dbHandler = new DatabaseHandler(getApplicationContext());
        user = dbHandler.getUserDetails();
        TextView userName = (TextView) findViewById(R.id.userName);
        userName.setText(user.get("name"));
        dbHandler.close();

and this works fine, but the request for the friends list looks like

    public HashMap<String, String> getFriendshipDetails(){

    HashMap<String,String> user = new HashMap<String,String>();
    String selectQuery = "SELECT * FROM " + TABLE_LOGIN;
    SQLiteDatabase db = this.getReadableDatabase();
    //Cursor cursor = db.query(TABLE_LOGIN, columns, null, null, null, null, null);
    Cursor cursor = db.rawQuery(selectQuery, null);
    // Move to first row
    cursor.moveToFirst();
    if(cursor.getCount() > 0){
        user.put("user1_id", cursor.getString(1));
        user.put("user2_id", cursor.getString(2));
        user.put("relationship_id", cursor.getString(3));
        user.put("time_created", cursor.getString(4));
    }
    cursor.close();
    db.close();
    // return user
    return user;

}

very similar, at first it did not call anything at all, it kept force closing the app, all very frustrating. I updated the database number, and it doesn't force close, but it brings everything i request as null.

        dbHandler = new FriendshipHandler(getApplicationContext());
    user = dbHandler.getFriendshipDetails();
    TextView userName = (TextView) findViewById(R.id.textView);
    userName.setText(user.get("user1_id"));
    dbHandler.close();

Thank you very much in advance...This means a lot for me!

0

There are 0 answers