'Last element is printed twice, Android Studio Cursor

My code creates a duplication of the last entry in the cursor. The text in the textview looks something like this:

Peter,23
Paul,40
Anastasia,20
Anastasia,20

Here is the code I have written.

public void doList(View v){
        LinearLayout l = (LinearLayout)findViewById(R.id.mainView);
        Cursor c = myDB.doQuery("SELECT name, age from students");
        String out;

        while(c.moveToNext()) {
            TextView t = new TextView(this);
            String name = c.getString(c.getColumnIndexOrThrow("name"));
            String age = c.getString(c.getColumnIndexOrThrow("age"));
            out = name + "," + age;
            l.addView(t);
            t.setText(out);
        }
        c.close();
    }


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source