title: Why am I getting an java.lang.IllegalArgumentException: the bind value at index 1 is null in this case?
body: <p>I know what an <code>java.lang.IllegalArgumentException: the bind value at index 1 is null</code> means and what causes the error. I my case I am still unable to find the reason for such an error in my case.</p>
  
  <p><strong>So, what do I intend to achieve?</strong></p>
  
  <p>I have 4 columns in my SQLite database table. I want to find the sum of each column and again find the sum of these four results. The row values for sum is filtered based on the product name chosen by the user from the autoCompleteTextView.</p>
  
  <p><strong>Where am I getting the error?</strong></p>
  
  <p>my stackTrace says I am getting the error in the line beginning with <em>Cursor c = db.query...</em> in the below code. The following code is part of my db file of my android project.</p>
  
  <pre><code>    public int addPurchaseQuantity(String itemName) {
      SQLiteDatabase db = helper.getReadableDatabase();
      int result = 0;
      String selection = VivzHelper.COLUMN_ADD_PURCHASE_ITEM_NAME + " =? ";
      String[] selectionArgs = {itemName};
      Cursor c = db.query(VivzHelper.ADD_PURCHASE_TABLE,
              new String[]{"sum(" + VivzHelper.COLUMN_ADD_PURCHASE_ITEM_QUANTITY + ")"},
              selection,
              selectionArgs,
              null,
              null,
              null);
      if (c.moveToFirst()) {
          result = c.getInt(0);
      }
      c.close();
      return result;
  }
  </code></pre>
  
  <p>The itemName is obtained from the autoCompleteTextView based on user selection.</p>
  
  <pre><code>        String[] autoCompleteName = vivzHelper.getInventoryNameFilterBySupplierName(vivzHelper.getSupplierID(param1));
      ArrayAdapter&lt;String&gt; NameAdapter = new ArrayAdapter&lt;&gt;(this, android.R.layout.simple_list_item_1, autoCompleteName);
      addPurchaseItemName.setThreshold(1);// starts working from first char
      addPurchaseItemName.setAdapter(NameAdapter);
  
      addPurchaseItemName.setOnItemClickListener(new AdapterView.OnItemClickListener() {
  
          public void onItemClick(AdapterView&lt;?&gt; arg0, View arg1, int arg2, long arg3) {
              itemName = String.valueOf(arg0.getItemAtPosition(arg2));
          }
      });
  </code></pre>
  
  <p>My stackTrace is also pointing to the following code of the java activity file.</p>
  
  <pre><code>int purchaseQty = vivzHelper.addPurchaseQuantity(itemName);
  </code></pre>
  
  <p>Here is my stackTrace</p>
  
  <pre><code>04-21 00:09:58.274  21975-21975/com.example.bharathduraiswamy.comboedittext E/AndroidRuntime﹕ FATAL EXCEPTION: main
  java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.bharathduraiswamy.comboedittext/com.example.bharathduraiswamy.comboedittext.AddPurchase}: java.lang.IllegalArgumentException: the bind value at index 1 is null
          at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2313)
          at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2365)
          at android.app.ActivityThread.access$600(ActivityThread.java:156)
          at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
          at android.os.Handler.dispatchMessage(Handler.java:99)
          at android.os.Looper.loop(Looper.java:153)
          at android.app.ActivityThread.main(ActivityThread.java:5336)
          at java.lang.reflect.Method.invokeNative(Native Method)
          at java.lang.reflect.Method.invoke(Method.java:511)
          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
          at dalvik.system.NativeStart.main(Native Method)
   Caused by: java.lang.IllegalArgumentException: the bind value at index 1 is null
          at android.database.sqlite.SQLiteProgram.bindString(SQLiteProgram.java:164)
          at android.database.sqlite.SQLiteProgram.bindAllArgsAsStrings(SQLiteProgram.java:200)
          at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:47)
          at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1314)
          at android.database.sqlite.SQLiteDatabase.queryWithFactory(SQLiteDatabase.java:1161)
          at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1032)
          at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1200)
          at com.example.bharathduraiswamy.comboedittext.VivzDatabaseAdapter.addPurchaseQuantity(VivzDatabaseAdapter.java:2011)
          at com.example.bharathduraiswamy.comboedittext.AddPurchase.aggregateQty(AddPurchase.java:531)
          at com.example.bharathduraiswamy.comboedittext.AddPurchase.onCreate(AddPurchase.java:133)
          at android.app.Activity.performCreate(Activity.java:5122)
          at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1081)
          at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2277)
          at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2365)
          at android.app.ActivityThread.access$600(ActivityThread.java:156)
          at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
          at android.os.Handler.dispatchMessage(Handler.java:99)
          at android.os.Looper.loop(Looper.java:153)
          at android.app.ActivityThread.main(ActivityThread.java:5336)
          at java.lang.reflect.Method.invokeNative(Native Method)
          at java.lang.reflect.Method.invoke(Method.java:511)
          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
          at dalvik.system.NativeStart.main(Native Method)
  </code></pre>
  
  <p>Can someone tell me where actually am I going wrong?</p>
  
  <p><strong>Update 01 : onCreate() from AddPurchase activity added</strong></p>
  
  <pre><code>    @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.add_purchase);
  
      // Set a toolbar to replace the action bar
      Toolbar myToolbar = (Toolbar) findViewById(R.id.toolbar_addPurchase);
      setSupportActionBar(myToolbar);
      myToolbar.setNavigationIcon(R.drawable.logo);
  
      //Disable the Toolbar Title
      getSupportActionBar().setDisplayShowTitleEnabled(false);
  
      // Adding UP icon for Setting Activity
      getSupportActionBar().setHomeButtonEnabled(true);
      getSupportActionBar().setDisplayHomeAsUpEnabled(true);
  
      SharedPreferences myPreferences = getSharedPreferences("sharedSupplierData", Context.MODE_PRIVATE);
      param1 = myPreferences.getString("sharedSupplierName", DEFAULT);
      if (param1.equals(DEFAULT)) {
          Message.message(this, "No data was found");
      }
  
      addPurchaseItemName = (AutoCompleteTextView) findViewById(R.id.addPurchaseProductName);
      addPurchaseItemQty = (EditText) findViewById(R.id.addPurchaseProductQuantity);
      addPurchaseCostPrice = (EditText) findViewById(R.id.addPurchaseCostPrice);
      addPurchaseSalePrice = (EditText) findViewById(R.id.addPurchaseSalePrice);
      myDate = (TextView) findViewById(R.id.addPurchaseDatum);
      purchaseSum = (TextView) findViewById(R.id.addPurchaseSum);
      primarySpinner = (Spinner) findViewById(R.id.toolbar_spinner);
      vivzHelper = new VivzDatabaseAdapter(this);
  
      showDialogOnButtonClick();
      populateListView();
  
      String[] autoCompleteName = vivzHelper.getInventoryNameFilterBySupplierName(vivzHelper.getSupplierID(param1));
      ArrayAdapter&lt;String&gt; NameAdapter = new ArrayAdapter&lt;&gt;(this, android.R.layout.simple_list_item_1, autoCompleteName);
      addPurchaseItemName.setThreshold(1);// starts working from first char
      addPurchaseItemName.setAdapter(NameAdapter);
  
      addPurchaseItemName.setOnItemClickListener(new AdapterView.OnItemClickListener() {
  
          public void onItemClick(AdapterView&lt;?&gt; arg0, View arg1, int arg2, long arg3) {
              itemName = String.valueOf(arg0.getItemAtPosition(arg2));
          }
      });
  
      Message.message(this, ("Item Name  = " + itemName));
  
      aggregateQty();
  
      //Initializing an Adapter
      ArrayAdapter&lt;String&gt; toolbar_adapter = new ArrayAdapter&lt;&gt;(
              this, android.R.layout.simple_spinner_dropdown_item, primarySpinner_array);
      //Providing the Resource xml for Drop down Layout
      toolbar_adapter.setDropDownViewResource(R.layout.custom_simple_spinner_dropdown_item);
      primarySpinner.setAdapter(toolbar_adapter);
  
      //Setting a default Spinner value before onItemClick
      primarySpinner.setSelection(0);
      //Initializing an OnItemClick Listener for Spinner Item
      primarySpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
  
          @Override
          public void onItemSelected(AdapterView&lt;?&gt; arg0, View arg1, int arg2, long arg3) {
              int position_toolbar = primarySpinner.getSelectedItemPosition();
  
              //Changing Spinner TextSize and Text Color
              ((TextView) arg0.getChildAt(0)).setTextColor(Color.WHITE);
              ((TextView) arg0.getChildAt(0)).setTextSize(20);
              //Changing Spinner Pointer Color - partially effective
              primarySpinner.getBackground().setColorFilter(getResources().getColor(R.color.White), PorterDuff.Mode.SRC_ATOP);
  
              //Using Switch to move to other Activities
              Intent intent_spinner;
              switch (arg2) {
                  case 1:
                      intent_spinner = new Intent(AddPurchase.this, SupplierDues.class);
                      AddPurchase.this.startActivity(intent_spinner);
                      break;
                  case 2:
                      intent_spinner = new Intent(AddPurchase.this, SupplierReturns.class);
                      AddPurchase.this.startActivity(intent_spinner);
                      break;
                  case 3:
                      intent_spinner = new Intent(AddPurchase.this, SupplierBalanceSheet.class);
                      AddPurchase.this.startActivity(intent_spinner);
                      break;
                  case 4:
                      intent_spinner = new Intent(AddPurchase.this, AddSupplier.class);
                      AddPurchase.this.startActivity(intent_spinner);
                      break;
                  default:
                      break;
              }
              //Changing Spinner Pointer Color - partially effective
              primarySpinner.getBackground().setColorFilter(getResources().getColor(R.color.White), PorterDuff.Mode.SRC_ATOP);
              //Setting a default Spinner value after onItemClick
              primarySpinner.setSelection(0);
          }
  
          @Override
          public void onNothingSelected(AdapterView&lt;?&gt; arg0) {
              // TODO Auto-generated method stub
          }
      });
  }
  </code></pre>
  
  <p><strong>Update 02 : aggregateQty() from when the addPurchaseQuantity() is called</strong></p>
  
  <pre><code>    public void aggregateQty() {
  
      int purchaseQty = vivzHelper.addPurchaseQuantity(itemName);
      int saleQty = vivzHelper.addSaleQuantity(itemName);
      int supplierRtnQty = vivzHelper.returnedToSupplierQuantity(itemName, rtnPrice);
      int supplierRtnScrapQty = vivzHelper.returnedToSupplierForScrapQuantity(itemName, rtnPrice);
      int customerRtnQty = vivzHelper.returnedByCustomerQuantity(itemName, rtnPrice);
  
      if (itemName.length() != 0) {
          availableQuantity = String.valueOf(purchaseQty - saleQty - supplierRtnQty - supplierRtnScrapQty + customerRtnQty);
          addPurchaseItemQty.setHint(availableQuantity);
  
          Message.message(this, ("Item Name  = " + itemName + "\n" +
                  "Purchase Quantity = " + purchaseQty + "\n" +
                  "Sale Quantity = " + saleQty + "\n" +
                  "Supplier Return Quantity = " + supplierRtnQty + "\n" +
                  "Customer Return Quantity = " + customerRtnQty));
  
      } else {
          Message.message(this, "Please Select an Item");
      }
  }
  </code></pre>