title: Why java.lang.IllegalArgumentException?
body: <p>I have a method which when supplied an ID as parameter returns a collection of meter readings for that person with that ID.</p>
  
  <pre><code>public List&lt;VMeterReadings&gt; GetIndividualReading(int id){
       List&lt;VMeterReadings&gt; individual = new ArrayList&lt;VMeterReadings&gt;();
          String selectQuery = " SELECT " + READINGDATEVIEW + "," + CurrentREADING + ","+ PrevREADINGDATE +","+ prevREADING +","+ UNITs+ ","+ RATE + ","+ AMOUNT + " FROM "
                             + VIEW_DETAILEDREADING + " Where " + KEY_ID + " = "+id + "  Order by " + READINGDATE + " DESC ";
  
          SQLiteDatabase db = this.getReadableDatabase();     
          Cursor c = db.rawQuery(selectQuery, null);
       if(c.moveToFirst()){
  
          do{
              VMeterReadings t =new VMeterReadings();                 
              try {
                  t.setReadingDate(fm.parse(c.getString(c.getColumnIndex(READINGDATE))));
              } catch (ParseException e) {
                  // TODO Auto-generated catch block
                  Log.e("parsing Reading date",e.toString());
              }
              t.setCurrentReading(c.getDouble(c.getColumnIndex(CurrentREADING)));
              try {
                  t.setPreviousReadingDate(fm.parse(c.getString(c.getColumnIndex(PrevREADINGDATE))));
              } catch (ParseException e) {
                  // TODO Auto-generated catch block
                  Log.e("parsing current reading",e.toString());
              }
              t.setPreviousMeterReading(c.getDouble(c.getColumnIndex(prevREADING)));
              t.setUnits(c.getDouble(c.getColumnIndex(UNITs)));
              t.setRate(c.getDouble(c.getColumnIndex(RATE)));
              t.setAmount(c.getDouble(c.getColumnIndex(AMOUNT)));
              individual.add(t);
          } while(c.moveToNext());
          }
       c.close();
       db.close();
       return individual;
  }
  </code></pre>
  
  <p>My aim is to be able to call that method from a class which will supply the ID in its constructor . I created the class and it extends the BaseAdapter.
  This is because i want to load the return data into a custom layout file.</p>
  
  <p>I have the xml file made.</p>
  
  <p>Here is the class that extends the base adapter.</p>
  
  <pre><code>package com.example.metermanager;
  
  import java.text.DecimalFormat;
  import java.text.SimpleDateFormat;
  import java.util.ArrayList;
  import java.util.List;
  import java.util.Locale;
  
  import meter.manager.helper.MyDatabaseAdapter;
  import meters.model.VMeterReadings;
  import android.content.Context;
  import android.util.Log;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.BaseAdapter;
  import android.widget.TextView;
  
  public class IndividualReadings extends BaseAdapter {
  
      @SuppressWarnings("unused")
      private Context context;
      private int id;
      MyDatabaseAdapter db;
      private static String DB_NAME="meterapp.sqlite";    
      private List&lt;VMeterReadings&gt; readings =new ArrayList&lt;VMeterReadings&gt;();
      DecimalFormat df = new DecimalFormat("#,###,###,###");
      SimpleDateFormat fm =new SimpleDateFormat("dd/MM/yyyy");
  public IndividualReadings(Context context1, int myid) {     
          this.context=context1;
          this.id=myid;
          MyDatabaseAdapter db= new  MyDatabaseAdapter( context1,DB_NAME);
          readings=db.GetIndividualReading(myid);
      }
  
  
  
      @Override
      public int getCount() {
          // TODO Auto-generated method stub
          return readings.size();
      }
  
      @Override
      public Object getItem(int index) {
          // TODO Auto-generated method stub
          return getItem(index);
      }
  
      @Override
      public long getItemId(int index) {
          // TODO Auto-generated method stub
          return index;
      }
  
      @Override
      public View getView(int index, View view, ViewGroup parent) {
          try{
  
              if (view ==null){
                  LayoutInflater inflater=
                          LayoutInflater.from(parent.getContext());
                        view =inflater.inflate(R.layout.individual_reading,parent,false);               
  
              }       
  
              VMeterReadings reading =readings.get(index);    
              // testing whether data returned.
              //correct data returned
              Log.e("readingDtae",fm.format(reading.getReadingDate()));
              Log.e("Reading",df.format(reading.getCurrentReading()));
              Log.e("PreviousReadingDate",fm.format(reading.getPreviousReadingDate()));
              Log.e("PreviousReading",df.format(reading.getPreviousMeterReading()));
  
  
              TextView readingdateTextView =(TextView)
                      view.findViewById(R.id.textView8);
  
              readingdateTextView.setText(fm.format(reading.getReadingDate()));
  
              TextView currentreadingTextView =(TextView)
                      view.findViewById(R.id.textView9);      
              currentreadingTextView.setText( Double.toString((reading.getCurrentReading())));
  
  
              TextView previoustreadingdateTextView =(TextView)
                      view.findViewById(R.id.textView10);     
              previoustreadingdateTextView.setText(df.format((reading.getPreviousReadingDate())));
  
               TextView previousmeterReading =(TextView)
                          view.findViewById(R.id.textView11);     
               previousmeterReading.setText(Double.toString((reading.getPreviousMeterReading())));
  
               TextView units =(TextView)
                          view.findViewById(R.id.textView12);     
                   units.setText(Double.toString((((reading.getUnits())))));      
  
                   TextView rate =(TextView)
                              view.findViewById(R.id.textView13);     
                       rate.setText(Double.toString(reading.getRate()));                       
                           TextView amountTextView =(TextView)
                                      view.findViewById(R.id.textView14);     
                               amountTextView.setText(df.format((reading.getAmount()))); 
  
  
              }catch(Exception e)
              {
                  Log.e("Error loading data in listbox",e.toString());
              }
              return view;
      }
  }
  </code></pre>
  
  <p>In the constructor</p>
  
  <pre><code>public IndividualReadings(Context context1, int myid) {     
          this.context=context1;
          this.id=myid;
          MyDatabaseAdapter db= new  MyDatabaseAdapter( context1,DB_NAME);
          readings=db.GetIndividualReading(myid);
      }
  </code></pre>
  
  <p>I want the calling code to supply the parameter myid which the class should use when calling the method to get the collection of meter readings...</p>
  
  <p>Example of how i call the class is below in the spinner control. The spinner is a list of tenants. The code gets the ID of the selected  tenant and supply it as iD to use by the class to get the collection and fill the xml file for display.</p>
  
  <pre><code>public void onItemSelected(AdapterView&lt;?&gt; arg0, View arg1, int arg2,
              long arg3) {
          try{
              int pos = spinner.getSelectedItemPosition();
              // get the tenant selected  in the list
              TenantList tenant=(TenantList)readings.get(pos);
              // get the ID
              int id =tenant.get_id();
              // instantiate the get individual readings class and pass the id as the parameter
              IndividualReadings individualreadings;  
              individualreadings= new IndividualReadings(this,id);
              ListView listview =(ListView)findViewById(R.id.reading_list);           
              listview.setBackgroundColor(color.holo_orange_dark);    
  
              listview.setAdapter(individualreadings);
              } catch(Exception e)
              {
                  Log.e("Spinner Error", e.toString());
              }
  </code></pre>
  
  <p>The metere readings are displayed in a listview control.</p>
  
  <p>I get the error i mentioned in the IndivualReadings class in the method getView(which is supposed to fill the custom view with data).
  Any ideas on how to solve the problem?</p>
  
  <p>I have so far tested and found that the id parameter is correctly passed and right data returned.</p>
  
  <p>But i dont why i get that error in the getView method.</p>
  
  <p>Ronald</p>
  
  <p>Here is the Logcat entries</p>
  
  <pre><code>01-30 12:41:20.782: D/dalvikvm(387): GC_EXTERNAL_ALLOC freed 88K, 52% free 2622K/5379K, external 515K/517K, paused 102ms
  01-30 12:41:20.802: E/Database(387): close() was never explicitly called on database 'data/data/com.example.metermanager/databases/meterapp.sqlite' 
  01-30 12:41:20.802: E/Database(387): android.database.sqlite.DatabaseObjectNotClosedException: Application did not close the cursor or database object that was opened here
  01-30 12:41:20.802: E/Database(387):    at android.database.sqlite.SQLiteDatabase.&lt;init&gt;(SQLiteDatabase.java:1847)
  01-30 12:41:20.802: E/Database(387):    at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:820)
  01-30 12:41:20.802: E/Database(387):    at meter.manager.helper.MyDatabaseAdapter.openDataBase(MyDatabaseAdapter.java:191)
  01-30 12:41:20.802: E/Database(387):    at meter.manager.helper.MyDatabaseAdapter.&lt;init&gt;(MyDatabaseAdapter.java:102)
  01-30 12:41:20.802: E/Database(387):    at com.example.metermanager.IndividualReadings.&lt;init&gt;(IndividualReadings.java:32)
  01-30 12:41:20.802: E/Database(387):    at com.example.metermanager.MainActivity.onItemSelected(MainActivity.java:105)
  01-30 12:41:20.802: E/Database(387):    at android.widget.AdapterView.fireOnSelected(AdapterView.java:871)
  01-30 12:41:20.802: E/Database(387):    at android.widget.AdapterView.access$200(AdapterView.java:42)
  01-30 12:41:20.802: E/Database(387):    at android.widget.AdapterView$SelectionNotifier.run(AdapterView.java:837)
  01-30 12:41:20.802: E/Database(387):    at android.os.Handler.handleCallback(Handler.java:587)
  01-30 12:41:20.802: E/Database(387):    at android.os.Handler.dispatchMessage(Handler.java:92)
  01-30 12:41:20.802: E/Database(387):    at android.os.Looper.loop(Looper.java:123)
  01-30 12:41:20.802: E/Database(387):    at android.app.ActivityThread.main(ActivityThread.java:3683)
  01-30 12:41:20.802: E/Database(387):    at java.lang.reflect.Method.invokeNative(Native Method)
  01-30 12:41:20.802: E/Database(387):    at java.lang.reflect.Method.invoke(Method.java:507)
  01-30 12:41:20.802: E/Database(387):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
  01-30 12:41:20.802: E/Database(387):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
  01-30 12:41:20.802: E/Database(387):    at dalvik.system.NativeStart.main(Native Method)
  01-30 12:41:22.862: E/readingDtae(387): 20/01/2014
  01-30 12:41:22.862: E/Reading(387): 150
  01-30 12:41:22.872: E/PreviousReadingDate(387): 10/01/2014
  01-30 12:41:22.872: E/PreviousReading(387): 100
  01-30 12:41:22.872: E/Error loading data in listbox(387): java.lang.IllegalArgumentException
  01-30 12:41:22.903: E/readingDtae(387): 10/01/2014
  01-30 12:41:22.903: E/Reading(387): 100
  01-30 12:41:22.903: E/PreviousReadingDate(387): 01/01/2014
  01-30 12:41:22.903: E/PreviousReading(387): 0
  01-30 12:41:22.912: E/Error loading data in listbox(387): java.lang.IllegalArgumentException
  01-30 12:41:22.923: E/readingDtae(387): 20/01/2014
  01-30 12:41:22.933: E/Reading(387): 150
  01-30 12:41:22.933: E/PreviousReadingDate(387): 10/01/2014
  01-30 12:41:22.933: E/PreviousReading(387): 100
  01-30 12:41:22.943: E/Error loading data in listbox(387): java.lang.IllegalArgumentException
  01-30 12:41:23.063: V/Path(387): data/data/com.example.metermanager/databases/
  01-30 12:41:23.063: V/name(387): meterapp.sqlite
  01-30 12:41:23.063: E/CheckPath(387): data/data/com.example.metermanager/databases/meterapp.sqlite
  01-30 12:41:23.242: D/Exits(387): Db Exist
  01-30 12:41:23.412: E/readingDtae(387): 20/01/2014
  01-30 12:41:23.412: E/Reading(387): 160
  01-30 12:41:23.412: E/PreviousReadingDate(387): 10/01/2014
  01-30 12:41:23.423: E/PreviousReading(387): 60
  01-30 12:41:23.423: E/Error loading data in listbox(387): java.lang.IllegalArgumentException
  01-30 12:41:23.452: E/readingDtae(387): 10/01/2014
  01-30 12:41:23.462: E/Reading(387): 60
  01-30 12:41:23.462: E/PreviousReadingDate(387): 01/01/2014
  01-30 12:41:23.462: E/PreviousReading(387): 0
  01-30 12:41:23.472: E/Error loading data in listbox(387): java.lang.IllegalArgumentException
  01-30 12:41:23.483: E/readingDtae(387): 20/01/2014
  01-30 12:41:23.483: E/Reading(387): 160
  01-30 12:41:23.502: E/PreviousReadingDate(387): 10/01/2014
  01-30 12:41:23.502: E/PreviousReading(387): 60
  01-30 12:41:23.502: E/Error loading data in listbox(387): java.lang.IllegalArgumentException
  01-30 12:41:23.523: E/readingDtae(387): 20/01/2014
  01-30 12:41:23.523: E/Reading(387): 160
  01-30 12:41:23.523: E/PreviousReadingDate(387): 10/01/2014
  01-30 12:41:23.532: E/PreviousReading(387): 60
  01-30 12:41:23.532: E/Error loading data in listbox(387): java.lang.IllegalArgumentException
  </code></pre>