title: How to retrieve data from sqlite to show on textview
body: <p>I searched a lot I found issue that relate with my problem, but i fixed already, it still error I don't know why please help me to fix it.</p>
  
  <p>I want to retrive data from getNotname method to show in textview but it errors I don't know why, I just copy getAllContacts method in DatabaseHandler class and I adjusted a little bit query in getNotename.</p>
  
  <p><strong>In getAllContacts</strong>    String selectQuery = "SELECT  * FROM " + TABLE_SONG_DETAIL;</p>
  
  <p><strong>In getNotename</strong>       String selectQuery = "SELECT  "+ KEY_N_NAME +" FROM " + TABLE_SONG_DETAIL+ "  WHERE KEY_ID = '2';";  </p>
  
  <p>but in mainactivity when I call getNotename, it errors, it didn't show anything. On the other hand when I call getAllContacts instead of getNotename , It's okay data will show on textview. I just want to know why when I adapt a little bit query in getNotename then it errors.</p>
  
  <pre><code>               **List&lt;Contact&gt; contacts = db.getNotename();**  // When I call getNotename method, It errors but when I change to call to getAllContacts, It can show data on textview.
  </code></pre>
  
  <p>This is my code</p>
  
  <p>DatabaseHandler class</p>
  
  <pre><code>public class DatabaseHandler extends SQLiteOpenHelper {
  
  
  
      // All Static variables
      // Database Version
      private static final int DATABASE_VERSION = 1;
  
      // Database Name
      private static final String DATABASE_NAME = "PianoNote";
  
      // Contacts table name
      private static final String TABLE_SONG_DETAIL = "songDetail";
  
      // Contacts Table Columns names
      private static final String KEY_ID = "id";
      private static final String KEY_S_NAME = "songname";
      private static final String KEY_N_NAME = "notename";
      private static final String KEY_TIME = "time";
  
  
      public DatabaseHandler(Context context) {
          super(context, DATABASE_NAME, null, DATABASE_VERSION);
      }
  
      // Creating Tables
      @Override
      public void onCreate(SQLiteDatabase db) {
          String CREATE_CONTACTS_TABLE = "CREATE TABLE " + TABLE_SONG_DETAIL + "("
                  + KEY_ID + " INTEGER PRIMARY KEY," + KEY_S_NAME + " TEXT," + KEY_N_NAME + " TEXT,"
                  + KEY_TIME + " TEXT" + ")";
          db.execSQL(CREATE_CONTACTS_TABLE);
      }
  
      // Upgrading database
      @Override
      public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
          // Drop older table if existed
          db.execSQL("DROP TABLE IF EXISTS " + TABLE_SONG_DETAIL);
  
          // Create tables again
          onCreate(db);
      }
  
  
  
      // Adding new data
      void addContact(Contact contact) {
          SQLiteDatabase db = this.getWritableDatabase();
  
          ContentValues values = new ContentValues(); //import android.content.ContentValues
          values.put(KEY_S_NAME, contact.getsongName()); // Song Name
          values.put(KEY_N_NAME, contact.getNotename()); //  Note name
          values.put(KEY_TIME, contact.getTime()); // Time
  
  
          // Inserting Row
          db.insert(TABLE_SONG_DETAIL, null, values);
          db.close(); // Closing database connection
      }
  
  
  
      // Getting All Data in Table
      **public List&lt;Contact&gt; getAllContacts() {**
          List&lt;Contact&gt; contactList = new ArrayList&lt;Contact&gt;();
          // Select All Query
          String selectQuery = "SELECT  * FROM " + TABLE_SONG_DETAIL;
  
          SQLiteDatabase db = this.getWritableDatabase();
          Cursor cursor = db.rawQuery(selectQuery, null);
  
          // looping through all rows and adding to list
          if (cursor.moveToFirst()) {
              do {
                  Contact contact = new Contact();
                  contact.setID(Integer.parseInt(cursor.getString(0)));
                  contact.setsongName(cursor.getString(1));
                  contact.setNotename(cursor.getString(2));
                  contact.setTime(cursor.getString(3));
                  // Adding contact to list
                  contactList.add(contact);
              } while (cursor.moveToNext());
          }
  
          // return contact list
          return contactList;
      }
  
  
  
      // Getting  Notename
      **public List&lt;Contact&gt; getNotename() {**
          List&lt;Contact&gt; contactList = new ArrayList&lt;Contact&gt;();  
          // Select  Query
  
          String selectQuery = "SELECT  "+ KEY_N_NAME +" FROM " + TABLE_SONG_DETAIL+ "  WHERE KEY_ID = '2';";
  
  
          SQLiteDatabase db = this.getWritableDatabase();
          Cursor cursor = db.rawQuery(selectQuery, null);
  
          // looping through all rows and adding to list
          if (cursor.moveToFirst()) {
              do {
                  Contact contact = new Contact();
  
                  contact.setID(Integer.parseInt(cursor.getString(0)));
                  contact.setsongName(cursor.getString(1));
                  contact.setNotename(cursor.getString(2));
                  contact.setTime(cursor.getString(3));
  
                  // Adding contact to list
                  contactList.add(contact);
              } while (cursor.moveToNext());
          }
  
          // return contact list
          return contactList;
      }
      }
  </code></pre>
  
  <p>MainActivity class</p>
  
  <pre><code>public class MainActivity extends Activity {
  
      SQLiteDatabase mDb;
      Cursor mCursor;
  
  
      @Override
          public void onCreate(Bundle savedInstanceState) {
              super.onCreate(savedInstanceState);
              setContentView(R.layout.activity_main);
              TextView note = (TextView)findViewById(R.id.textView1);
              DatabaseHandler db = new DatabaseHandler(this);
  
  
              // Inserting Data
              Log.d("Insert: ", "Inserting .."); 
  
  
              db.addContact(new Contact("Twinkle", "Do", "0.1"));   
              db.addContact(new Contact("Twinkle", "Do", "0.2"));    
              db.addContact(new Contact("Twinkle", "Sol", "0.3"));    
              db.addContact(new Contact("Twinkle", "Sol", "0.4"));    
              db.addContact(new Contact("Twinkle", "La", "0.5")); 
  
  
  
              // Reading all contacts
              Log.d("Reading: ", "Reading all contacts.."); 
  
  
              **List&lt;Contact&gt; contacts = db.getNotename();** 
  
                      StringBuilder builder = new StringBuilder();
                  for (Contact cn : contacts) {
                      builder.append(cn.getNotename());
  
  
                      // Writing Contacts to log
                      String log = "Id: "+cn.getID()+" ,SongName: " + cn.getsongName() + " ,NoteName: " + cn.getNotename()+ " ,Time: " + cn.getTime();
                      Log.d("Name: ", log);
                  }
  
                  // print show on textview
                  note.setText(builder.toString());
  
  
          }
  
  
          }
  </code></pre>
  
  <p>Contact class </p>
  
  <pre><code>package com.example.databasehandler.java;
  
  public class Contact {
  
  
  
          //private variables
          int _id;
          String _songname;
          String _note_name;
          String _time;
  
          // Empty constructor
          public Contact(){
  
          }
          // constructor
          public Contact(int id, String songname, String notename, String time){
              this._id = id;
              this._songname = songname;
              this._note_name = notename;
              this._time = time;
  
          }
  
          // constructor
          public Contact(String songname, String notename, String time){
              this._songname = songname;
              this._note_name = notename;
              this._time = time;
  
          }
          // getting ID
          public int getID(){
              return this._id;
          }
  
          // setting id
          public void setID(int id){
              this._id = id;
          }
  
          // getting name
          public String getsongName(){
              return this._songname;
          }
  
          // setting name
          public void setsongName(String songname){
              this._songname = songname;
          }
  
          // getting phone number
          public String getNotename(){
              return this._note_name;
          }
  
          // setting phone number
          public void setNotename(String notename){
              this._note_name = notename;
          }
  
       // getting phone number
          public String getTime(){
              return this._time;
          }
  
          // setting phone number
          public void setTime(String time){
              this._time = time;
          }
      }
  </code></pre>