vendredi 6 mai 2016

android activity crashes on update listview

i'm having a problem with an Android app.

The activity automatically restarts when I update the listview with different content, the original works well.

public void showGyroscopeData(View view) {

    obj.setAdapter(null);
    if(mydb.getAllGyroscopeRegists().size()!=0);
    ArrayList<String> array_list = new ArrayList<String>(mydb.getAllGyroscopeRegists());
    /*ArrayAdapter arrayAdapter=new ArrayAdapter(this,android.R.layout.simple_list_item_1, array_list);

    obj.setAdapter(arrayAdapter);*/
}

the app crashes when it gets the gyroscope regists from a sqlite database.

public ArrayList<String> getAllGyroscopeRegists() {
    ArrayList<String> arrayList = new ArrayList<String>();
    SQLiteDatabase db = this.getReadableDatabase();

    String[] columns = {ID, TIMESTAMP, X, Y, Z, CURRENTARM, USERNAME, MOVENAME };

    Cursor cursor = db.query(
            TABLE_GYROSCOPE_NAME,  // The table to query
            columns, // The columns to return
            null,
            null,                                // The columns for the WHERE clause
            null,                            // The values for the WHERE clause
            null,                                     // don't group the rows
            null                                     // don't filter by row groups
            //sortOrder                                 // The sort order
    );

    cursor.moveToFirst();

    while(!cursor.isAfterLast()) //itera linhas
    {
        StringBuilder paragraph=new StringBuilder();

        for(int i=0; i<cursor.getColumnCount();i++) {
            paragraph.append(cursor.getString(i) + " ");
        }

        arrayList.add(paragraph.toString());
        cursor.moveToNext();
    }
    return arrayList;
}

there's another sensor the accelerometer, and it works fine with just a few changes. There's no messages on the logcat.

Aucun commentaire:

Enregistrer un commentaire