O apk nãoabre e ocorre uma exception:
```03-26 20:42:25.978 6047-6047/com.paris.agenda E/CursorWindow: Failed to read row 0, column -1 from a CursorWindow which has 6 rows, 7 columns.
03-26 20:42:25.979 6047-6047/com.paris.agenda E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.paris.agenda, PID: 6047
java.lang.RuntimeException: Unable to resume activity {com.paris.agenda/com.paris.agenda.ListStudentsActivity}: java.lang.IllegalStateException: Couldn't read row 0, col -1 from CursorWindow. Make sure the Cursor is initialized correctly before accessing data from it.
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3103)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3134)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2481)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.IllegalStateException: Couldn't read row 0, col -1 from CursorWindow. Make sure the Cursor is initialized correctly before accessing data from it.
at android.database.CursorWindow.nativeGetString(Native Method)
at android.database.CursorWindow.getString(CursorWindow.java:438)
at
public StudentDao(Context context) { super(context, "Agenda", null, 2); }
@Override
public void onCreate(SQLiteDatabase db) {
String sql = "CREATE TABLE Students(id INTEGER PRIMARY KEY, name TEXT NOT NULL, address TEXT, phone TEXT, site TEXT, grade REAL, localPhoto TEXT); ";
db.execSQL(sql);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
String sql = "";
switch (oldVersion) {
case 1:
sql = "ALTER TABLE Students ADD COLUMN localPhot TEXT";
db.execSQL(sql);
}
}
public void insertStudent(Student student) {
SQLiteDatabase db = getWritableDatabase();
ContentValues data = getContentValues(student);
db.insert("Students", null, data);
}
private ContentValues getContentValues(Student student) {
ContentValues data = new ContentValues();
data.put("name", student.getName());
data.put("address", student.getAddress());
data.put("phone", student.getPhone());
data.put("site", student.getSite());
data.put("grade", student.getGrade());
data.put("localPhoto", student.getPhoto());
return data;
}
public List<Student> searchStudents() {
SQLiteDatabase db = getReadableDatabase();
Cursor c = db.rawQuery("SELECT * FROM Students ;", null);
List<Student> students = new ArrayList<Student>();
while (c.moveToNext()) {
Student student = new Student();
student.setId(c.getLong(c.getColumnIndex("id")));
student.setName(c.getString(c.getColumnIndex("name")));
student.setAddress(c.getString(c.getColumnIndex("address")));
student.setPhone(c.getString(c.getColumnIndex("phone")));
student.setSite(c.getString(c.getColumnIndex("site")));
student.setGrade(c.getDouble(c.getColumnIndex("grade")));
student.setPhoto(c.getString(c.getColumnIndex("localPhoto")));
students.add(student);
}
c.close();
return students;
}
public void delete(Student student) {
SQLiteDatabase db = getWritableDatabase();
String[] params = {String.valueOf(student.getId())};
db.delete("Students", "id=?", params);
}
public void updateStudent(Student student) {
SQLiteDatabase db = getWritableDatabase();
ContentValues date = getContentValues(student);
String[] params = {String.valueOf(student.getId())};
db.update("Students", date, "id=?", params);
}
}
`