我的主要活动中有一个列表视图,当我们点击它并且我有两个班级时,它会显示一个人的详细信息
EmployeeList.java - http://pastebin.com/5vPMKrCQ
DatabaseHelper.java - http://pastebin.com/NS7RR8E6
我的logcat中有以下异常。
05-09 16:58:10.278: E/CursorWindow(23310): Failed to read row 0, column -1 from a CursorWindow which has 2 rows, 3 columns.
05-09 16:58:10.368: E/AndroidRuntime(23310): java.lang.IllegalStateException: Couldn't read row 0, col -1 from CursorWindow. Make sure the Cursor is initialized correctly before accessing data from it.
答案 0 :(得分:1)
Cursor cursor = db.rawQuery("select * from employee_directory where _id " + id);
if (null != cursor&&cursor.moveToFirst()) {
String title= cursor.getString(cursor.getColumnIndex(DatabaseHelper.TITLE));
String membername= currsor.getString(cursor.getColumnIndex(DatabaseHelper.MEMBER_NAME));
}
答案 1 :(得分:0)
从数据库获取光标后,您可能还没有完成 cursor.moveToFirst()。
答案 2 :(得分:0)
尝试以下代码
setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> parent, View v,
int position, long id) {
//Your logic
}
}