title: Android : How to retrieve specific column in spinner from Sqlite
body: <p>I work with SQLite database in my Android application.I want only one column retrieved in spinner. When I run the application ,the application is crashing. And my log cat shows:</p>
  
  <blockquote>
    <p>Bad request for field slot 0,1. numRows = 1, numColumns = 1</p>
  </blockquote>
  
  <p>Below are the codes for retrieving data from database and put it into spinner (NewleadActivity.class).</p>
  
  <p>This is my Adapter class</p>
  
  <pre><code>public class DbHelper extends SQLiteOpenHelper
  {
       // Database Version
      @SuppressWarnings("unused")
      private static final int DATABASE_VERSION = 1;
  
     // Database Name
      static String DATABASE_NAME="define_products_database";
  
      // Labels table name
      public static final String TABLE_DEFINE_PRODUCT_NAME="define_products";
  
       // Labels Table Columns names
      public static final String KEY_PRODUCTS_NAME="product_name";
      public static final String KEY_PRODUCTS_DETAILS="products_details";
      public static final String KEY_ID="id";
  
      public DbHelper(Context context) {
          super(context, DATABASE_NAME, null, 1);
  
      }
  
      @Override
      public void onCreate(SQLiteDatabase db) {
          String CREATE_TABLE="CREATE TABLE "+TABLE_DEFINE_PRODUCT_NAME+" ("+KEY_ID+" INTEGER PRIMARY KEY, "+KEY_PRODUCTS_NAME+" TEXT, "+KEY_PRODUCTS_DETAILS+" TEXT)";
          db.execSQL(CREATE_TABLE);
  
      }
  
      @Override
      public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
          db.execSQL("DROP TABLE IF EXISTS "+TABLE_DEFINE_PRODUCT_NAME);
          onCreate(db);
  
      }
  
  
       /**
       * Getting all labels
       * returns list of labels
       * */
  
      public List&lt;String&gt; getAllLabels(){
          List&lt;String&gt; labels = new ArrayList&lt;String&gt;();
  
          // Select All Query
          String selectQuery = " SELECT " + KEY_PRODUCTS_NAME + " FROM "+ TABLE_DEFINE_PRODUCT_NAME;
  
          SQLiteDatabase db = this.getReadableDatabase();
          Cursor cursor = db.rawQuery(selectQuery, null);
  
          // looping through all rows and adding to list
          if (cursor.moveToFirst()) {
              do {
                  labels.add(cursor.getString(1));
              } while (cursor.moveToNext());
          }
  
          // closing connection
          cursor.close();
          db.close();
  
          // returning lables
          return labels;
      }
  
  }
  </code></pre>
  
  <p>This is the Activity code which is included spiner</p>
  
  <pre><code>public void onCreate(Bundle savedInstanceState)
      {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.new_lead_activity5);
  spinner_Products=(Spinner)findViewById(R.id.products_Spinner);
  
  loadSpinnerData();
  
  }
  
  
  
  private void loadSpinnerData() {
          // database handler
          DbHelper db = new DbHelper(getApplicationContext());
  
          // Spinner Drop down elements
          List&lt;String&gt; lables = db.getAllLabels();
  
          // Creating adapter for spinner
          ArrayAdapter&lt;String&gt; dataAdapter = new ArrayAdapter&lt;String&gt;(this,
                  android.R.layout.simple_spinner_item, lables);
  
          // Drop down layout style - list view with radio button
          dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
  
          // attaching data adapter to spinner
          spinner_Products.setAdapter(dataAdapter);
      }
  
  }
  </code></pre>
  
  <p>This is my Log cat.</p>
  
  <pre><code>11-27 11:28:28.548: E/AndroidRuntime(2150): FATAL EXCEPTION: main
  11-27 11:28:28.548: E/AndroidRuntime(2150): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.lead_management_project/com.lead_management_project.New_Lead_Activity5}: java.lang.IllegalStateException: get field slot from row 0 col 1 failed
  11-27 11:28:28.548: E/AndroidRuntime(2150):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
  11-27 11:28:28.548: E/AndroidRuntime(2150):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
  11-27 11:28:28.548: E/AndroidRuntime(2150):     at android.app.ActivityThread.access$1500(ActivityThread.java:117)
  11-27 11:28:28.548: E/AndroidRuntime(2150):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
  11-27 11:28:28.548: E/AndroidRuntime(2150):     at android.os.Handler.dispatchMessage(Handler.java:99)
  11-27 11:28:28.548: E/AndroidRuntime(2150):     at android.os.Looper.loop(Looper.java:123)
  11-27 11:28:28.548: E/AndroidRuntime(2150):     at android.app.ActivityThread.main(ActivityThread.java:3683)
  11-27 11:28:28.548: E/AndroidRuntime(2150):     at java.lang.reflect.Method.invokeNative(Native Method)
  11-27 11:28:28.548: E/AndroidRuntime(2150):     at java.lang.reflect.Method.invoke(Method.java:507)
  11-27 11:28:28.548: E/AndroidRuntime(2150):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
  11-27 11:28:28.548: E/AndroidRuntime(2150):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
  11-27 11:28:28.548: E/AndroidRuntime(2150):     at dalvik.system.NativeStart.main(Native Method)
  11-27 11:28:28.548: E/AndroidRuntime(2150): Caused by: java.lang.IllegalStateException: get field slot from row 0 col 1 failed
  11-27 11:28:28.548: E/AndroidRuntime(2150):     at android.database.CursorWindow.getString_native(Native Method)
  11-27 11:28:28.548: E/AndroidRuntime(2150):     at android.database.CursorWindow.getString(CursorWindow.java:329)
  11-27 11:28:28.548: E/AndroidRuntime(2150):     at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:49)
  11-27 11:28:28.548: E/AndroidRuntime(2150):     at com.db_mgmt.DbHelper.getAllLabels(DbHelper.java:65)
  11-27 11:28:28.548: E/AndroidRuntime(2150):     at com.lead_management_project.New_Lead_Activity5.loadSpinnerData(New_Lead_Activity5.java:123)
  11-27 11:28:28.548: E/AndroidRuntime(2150):     at com.lead_management_project.New_Lead_Activity5.onCreate(New_Lead_Activity5.java:80)
  11-27 11:28:28.548: E/AndroidRuntime(2150):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
  11-27 11:28:28.548: E/AndroidRuntime(2150):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
  11-27 11:28:28.548: E/AndroidRuntime(2150):     ... 11 more
  </code></pre>