0

所以我一直在为我和我的朋友之间建立一个社交网络,感觉像是无休止地工作,当我在编程方面变得更好时可能会更多。我已经成功制作了一个数据库,允许用户创建帐户,甚至添加朋友,但我似乎无法显示朋友?我可以显示来自用户帐户的任何信息,但不能显示朋友?要查看帐户上的内容,我会查询它

    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;
}

然后在活动中,我称之为

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

这很好用,但是对朋友列表的请求看起来像

    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;

}

非常相似,一开始它根本没有调用任何东西,它一直强制关闭应用程序,这一切都非常令人沮丧。我更新了数据库编号,它不会强制关闭,但它会将我请求的所有内容都设为空。

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

非常感谢您...这对我来说意义重大!

4

0 回答 0