title: How to return all different names in table (Android-Sqlite)
body: <p>I have a problem to return all different names from my database Table. The table have following columns:</p>
  
  <pre><code>    public static final String KEY_ID = "_id";
  public static final String KEY_NAME = "name";
  public static final String KEY_BETRAG = "betrag";
  public static final String KEY_GRUND = "grund";
  public static final String KEY_DATUM = "datum";
  public static final String KEY_ICONID = "icon";
  
      public static final int COL_ROWID = 0;
  public static final int COL_NAME = 1;
  public static final int COL_BETRAG = 2;
  public static final int COL_GRUND = 3;
  public static final int COL_DATUM = 4;
  public static final int COL_ICONID = 5;
  
  public static final String[] ALL_KEYS = new String[] {KEY_ID, KEY_NAME, KEY_BETRAG,KEY_GRUND, KEY_DATUM, KEY_ICONID};
  public static final String[] ALL_DIFFERENTNAMES = new String[] {KEY_NAME};
  
  private static final String DATABASE_CREATE_TABLE1 = 
              "create table " + DATABASE_TABLE1 
              + " (" + KEY_ID + " integer primary key autoincrement, "
              + KEY_NAME + " text not null, "
              + KEY_BETRAG + " real not null, "
              + KEY_GRUND + " text not null, "
              + KEY_DATUM + " text not null, "
              + KEY_ICONID + " integer not null"
              + ");";
  </code></pre>
  
  <p>With the following method, I want to return all different names, but it did not worked after all</p>
  
  <pre><code>    public Cursor getAllDifferentNames1() {
  
  //      String where = "SELECT DISTINCT " + KEY_NAME + " FROM " + DATABASE_TABLE1;
  
      Cursor c = db.query(true, DATABASE_TABLE1, ALL_DIFFERENTNAMES, null, null, null, null, null, null);
  
      if(c != null) {
          c.moveToFirst();
      }
  
      return c;
  }
  </code></pre>
  
  <p>When I run the application, I get this error message:</p>
  
  <pre><code>    01-04 16:18:54.878: E/AndroidRuntime(28638): FATAL EXCEPTION: main
  01-04 16:18:54.878: E/AndroidRuntime(28638): java.lang.IllegalArgumentException: column '_id' does not exist
  01-04 16:18:54.878: E/AndroidRuntime(28638):    at android.database.AbstractCursor.getColumnIndexOrThrow(AbstractCursor.java:302)
  01-04 16:18:54.878: E/AndroidRuntime(28638):    at android.widget.SimpleCursorAdapter.findColumns(SimpleCursorAdapter.java:333)
  01-04 16:18:54.878: E/AndroidRuntime(28638):    at android.widget.SimpleCursorAdapter.&lt;init&gt;(SimpleCursorAdapter.java:81)
  01-04 16:18:54.878: E/AndroidRuntime(28638):    at fragments.Schuldet_mir.populateListViewFromDB(Schuldet_mir.java:243)
  01-04 16:18:54.878: E/AndroidRuntime(28638):    at fragments.Schuldet_mir.onResume(Schuldet_mir.java:99)
  01-04 16:18:54.878: E/AndroidRuntime(28638):    at android.support.v4.app.Fragment.performResume(Fragment.java:1543)
  01-04 16:18:54.878: E/AndroidRuntime(28638):    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:963)
  01-04 16:18:54.878: E/AndroidRuntime(28638):    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1104)
  01-04 16:18:54.878: E/AndroidRuntime(28638):    at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
  01-04 16:18:54.878: E/AndroidRuntime(28638):    at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1467)
  01-04 16:18:54.878: E/AndroidRuntime(28638):    at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:472)
  01-04 16:18:54.878: E/AndroidRuntime(28638):    at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:141)
  01-04 16:18:54.878: E/AndroidRuntime(28638):    at android.support.v4.view.ViewPager.populate(ViewPager.java:1068)
  01-04 16:18:54.878: E/AndroidRuntime(28638):    at android.support.v4.view.ViewPager.populate(ViewPager.java:914)
  01-04 16:18:54.878: E/AndroidRuntime(28638):    at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1436)
  01-04 16:18:54.878: E/AndroidRuntime(28638):    at android.view.View.measure(View.java:15284)
  01-04 16:18:54.878: E/AndroidRuntime(28638):    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4816)
  01-04 16:18:54.878: E/AndroidRuntime(28638):    at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
  01-04 16:18:54.878: E/AndroidRuntime(28638):    at android.view.View.measure(View.java:15284)
  01-04 16:18:54.878: E/AndroidRuntime(28638):    at android.widget.LinearLayout.measureVertical(LinearLayout.java:861)
  01-04 16:18:54.878: E/AndroidRuntime(28638):    at android.widget.LinearLayout.onMeasure(LinearLayout.java:602)
  01-04 16:18:54.878: E/AndroidRuntime(28638):    at android.view.View.measure(View.java:15284)
  01-04 16:18:54.878: E/AndroidRuntime(28638):    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4816)
  01-04 16:18:54.878: E/AndroidRuntime(28638):    at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
  01-04 16:18:54.878: E/AndroidRuntime(28638):    at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2367)
  01-04 16:18:54.878: E/AndroidRuntime(28638):    at android.view.View.measure(View.java:15284)
  01-04 16:18:54.878: E/AndroidRuntime(28638):    at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1867)
  01-04 16:18:54.878: E/AndroidRuntime(28638):    at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1111)
  01-04 16:18:54.878: E/AndroidRuntime(28638):    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1292)
  01-04 16:18:54.878: E/AndroidRuntime(28638):    at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1009)
  01-04 16:18:54.878: E/AndroidRuntime(28638):    at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4236)
  01-04 16:18:54.878: E/AndroidRuntime(28638):    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725)
  01-04 16:18:54.878: E/AndroidRuntime(28638):    at android.view.Choreographer.doCallbacks(Choreographer.java:555)
  01-04 16:18:54.878: E/AndroidRuntime(28638):    at android.view.Choreographer.doFrame(Choreographer.java:525)
  01-04 16:18:54.878: E/AndroidRuntime(28638):    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711)
  01-04 16:18:54.878: E/AndroidRuntime(28638):    at android.os.Handler.handleCallback(Handler.java:615)
  01-04 16:18:54.878: E/AndroidRuntime(28638):    at android.os.Handler.dispatchMessage(Handler.java:92)
  01-04 16:18:54.878: E/AndroidRuntime(28638):    at android.os.Looper.loop(Looper.java:137)
  01-04 16:18:54.878: E/AndroidRuntime(28638):    at android.app.ActivityThread.main(ActivityThread.java:4872)
  01-04 16:18:54.878: E/AndroidRuntime(28638):    at java.lang.reflect.Method.invokeNative(Native Method)
  01-04 16:18:54.878: E/AndroidRuntime(28638):    at java.lang.reflect.Method.invoke(Method.java:511)
  01-04 16:18:54.878: E/AndroidRuntime(28638):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
  01-04 16:18:54.878: E/AndroidRuntime(28638):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
  01-04 16:18:54.878: E/AndroidRuntime(28638):    at dalvik.system.NativeStart.main(Native Method)
  </code></pre>
  
  <p>Can someone tell me, what I am doing wrong?</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>the method at the line 99 in class Schuldet_mir:</p>
  
  <pre><code>populateListViewFromDB();
  ......
  public void populateListViewFromDB() {                                      //ListView mit Werten aus der db befüllen
  
          getActivity().startManagingCursor(cursor = mainActivity.myDBHandler.getAllDifferentNames1());
  
          String[] dbSpaltenNamen = new String[] {DataBaseHandler.KEY_NAME,   //die spalteneinträge wie
                                                  DataBaseHandler.KEY_BETRAG, //angeordnet in die jeweiligen
                                                  DataBaseHandler.KEY_DATUM,  //id's des custom listzeile zuordnen
                                                  DataBaseHandler.KEY_ICONID};
  
          int[] zuListViewIDs = new int[] {R.id.txt_name,                     //hier die id's. name zu name
                                           R.id.txt_betrag,                   //betrag zu betrag...
                                           R.id.datum,
                                           R.id.list_userImage};
  
          SimpleCursorAdapter myCursorAdapter 
                  = new SimpleCursorAdapter
                              (getActivity(), R.layout.list_zeile, cursor, dbSpaltenNamen, zuListViewIDs);
  
          verliehenesGeld.setText("" + mFormater.formatDecimal(mainActivity.myDBHandler.getColBetragInTable1()));
  
          if(mainActivity.myDBHandler.getContactsCountInTable1() &gt; 0) {
              anzahlEinträge.setText("Einträge: " + mainActivity.myDBHandler.getContactsCountInTable1());
          }
          else {
              anzahlEinträge.setText("Keine Einträge");
          }
  
          listView.setAdapter(myCursorAdapter);
  }   
  </code></pre>