title: SQLite read data from a Database
body: <p>I am trying to get all data from database and display. but it is not working. can anyone tell what is the problem with the code? thank you. here is the code</p>
  
  <p>DataBase.java</p>
  
  <pre><code>//onlly the method
  
  public List&lt;Appo&gt; getAllData(){
  
          List&lt;Appo&gt; appos = new ArrayList&lt;&gt;();
  
          String APPOINTMENT_TABLE_NAME_SELECT_QUERY =
                  String.format("SELECT * FROM %s ",
                          APPOINTMENT_TABLE_NAME
                         );
  
          SQLiteDatabase db = getReadableDatabase();
          Cursor cursor = db.rawQuery(APPOINTMENT_TABLE_NAME_SELECT_QUERY, null);
          try {
              if (cursor.moveToFirst()) {
                  do {
                      Appo.title = cursor.getString(cursor.getColumnIndex(APPOINTMENT_COLUMN_TITLE));
                      Appo.time = cursor.getString(cursor.getColumnIndex(APPOINTMENT_COLUMN_TITLE));
                      Appo.details = cursor.getString(cursor.getColumnIndex(APPOINTMENT_COLUMN_DETAILS));
                      Appo.day = cursor.getString(cursor.getColumnIndex(APPOINTMENT_COLUMN_DAY));
                  } while(cursor.moveToNext());
              }
          } catch (Exception e) {
  
          } finally {
              if (cursor != null &amp;&amp; !cursor.isClosed()) {
                  cursor.close();
              }
          }
          return appos;
      }
  </code></pre>
  
  <p>Appo.java</p>
  
  <pre><code>public class Appo {
  
      public static int id;
      public static String title;
      public static String time;
      public static String details;
      public static String day;
  }
  </code></pre>
  
  <p>ViewAndEdit.java</p>
  
  <pre><code>public class ViewAndEdit extends AppCompatActivity {
  
      private TextView list;
      private Button btnview;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_view_and_edit);
  
          list =(TextView) findViewById(R.id.listappo);
          btnview =(Button)findViewById(R.id.btnview);
  
          final DataBase databaseHelper = DataBase.getInstance(this);
  
          btnview.setOnClickListener(new View.OnClickListener() {
              public void onClick(View v) {
                  final EditText title = new EditText(ViewAndEdit.this);
                  new AlertDialog.Builder(ViewAndEdit.this)
                          .setTitle("Edit")
                          .setView(title)
  
                          .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
                              public void onClick(DialogInterface dialog, int which) {
                                  // continue with delete
                              }
                          })
                          .setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
                              public void onClick(DialogInterface dialog, int which) {
  
                              }
                          })
                          .setIcon(android.R.drawable.ic_dialog_alert)
                          .show();
  
                  List&lt;Appo&gt; appos = databaseHelper.getAllData();
                  for (Appo appo : appos) {
                      list.setText(appo.toString());
                  }
              }
          });
  
      }
  }
  </code></pre>