檢索數據,我正在嘗試從sqlite的數據,但我不知道什麼是錯我的代碼從SQLite的
public class MainPage extends AppCompatActivity {
private RequestQueue requestQueue;
private String user,position;
private DatabaseHelper helper;
private List<User> user_position;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
helper=new DatabaseHelper(this);
if (helper.getUserlogin()==0) {
finish();
startActivity(new Intent(getApplicationContext(), LoginActivity.class));
}else {
setContentView(R.layout.activity_main_page);
user_position= helper.getUserPosition();
user = String.valueOf(user_position.get(0).getUserName());
position=String.valueOf(user_position.get(1).getUserPosition());
TextView textView = (TextView) findViewById(R.id.user);
textView.setText(user+"("+position+")");
}
}
,這是數據庫的讀寫方法
public List<User> getUserPosition() {
List<User> oList = new ArrayList<User>();
SQLiteDatabase db = getReadableDatabase();
Cursor cursor = db.query(ORDER_TABLE, null, null, null, null, null,
null);
User user = new User();
user.setUserName(cursor.getString(cursor
.getColumnIndex(ROW_USER)));
user.setUserPosition(cursor.getString(cursor
.getColumnIndex(ROW_POSITION)));
oList.add(user);
if (cursor != null)
cursor.close();
if (db != null)
db.close();
return oList;
}
什麼是不工作的清單?什麼是預期的結果和你得到什麼? – Rohit5k2
你在哪裏初始化'helper'? – Rohit5k2
是的我會編輯的問題更清楚@ Rohit5k2 –