title: java.lang.IllegalStateException: System services not available to Activities before onCreate() with ArrayAdapter<String>
body: <p>I am trying to run a ListActivity, which takes an array of filenames, which are to be inserted into the database. This is done by <code>insert()</code> in the following code. I am getting IllegalStateException at <code>ArrayAdapter&lt;String&gt;</code>. If I am calling the <code>insert()</code> function from another class. So, I am unable to define ArrayAdapter in the <code>onCreate()</code> method. Please see the following code, which is defining <code>insert()</code> method -</p>
  
  <pre><code>public class FileEvent extends ListActivity implements ObserverActivity{
  public static final String PREFS_NAME = "MyPreferencesFile";
  
  public String filename;
  public String path; 
  MyFileObserver myFileObserver; 
  public adapter info ;
  ArrayAdapter&lt;String&gt; adapterarr;
  ListView listView;
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      // TODO Auto-generated method stub
      super.onCreate(savedInstanceState);
     this.info  = new adapter(this);
      listView = (ListView) findViewById(android.R.id.list);
      setContentView(R.layout.fileeventlist);
      Bundle bundle = getIntent().getExtras();
  
      myFileObserver = new MyFileObserver("/storage/sdcard/DCIM/SAMPLE_IMAGES/");
          myFileObserver.registerObserver(this);
          myFileObserver.startWatching();
  
  /*  String var_from_prev_intent = bundle.getString("path");
      insert(var_from_prev_intent);
      SharedPreferences settings = getSharedPreferences (PREFS_NAME,0);
      String newpath = "";
      this.path = settings.getString("name",newpath);
      Log.v("New path in FileEvent : ",this.path);*/
  
  }
  
   protected void onPause(){
          myFileObserver.stopWatching();
          myFileObserver.unregisterObserver(this); 
        } 
  
        protected void onResume(){
          myFileObserver.registerObserver(this);
          myFileObserver.startWatching();
        }
  public void insert(String path) {
      // TODO Auto-generated method stub
      try{
  Log.v("FileName to insert : ",path);
  Log.v("a3","a3");
  this.info = new adapter(this);
  this.filename = path; 
  Log.v("a4","a4");
  if(info == null)
  {
      System.out.println("info is null here.");
  }
  else
  {
      System.out.println("info is not null here.");
  }
  int rowcount = info.getrowcountofpersons(); 
  Log.v("a5","a5"); 
  Log.v("rowcount in new list onCreate: ", ""+info.getrowcountofpersons()+"");
  Log.v("a6","a6");
  String[] values = new String[rowcount];
  Log.v("a7","a7");
  for(int i =1;i&lt;=rowcount;i++)
  {
      values[i-1]=info.getPersonList(i); 
      //Toast.makeText(getApplicationContext(), values[i-1],  Toast.LENGTH_LONG).show();
      System.out.println("in for loop now"+values[i-1]);
  } 
  Log.v("a8","a8");
  
  
   adapterarr = new ArrayAdapter&lt;String&gt;(this,
          android.R.layout.simple_list_item_1, values); 
  Log.v("a9","a9");
  
  Log.v("a10","a10");
  listView.setItemsCanFocus(false);
  Log.v("a11","a11");
  listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
  Log.v("a12","a12");
  
  // Assign adapter to List
  setListAdapter(adapterarr);  
  //  new Bullet(info).execute((Void)null);
  Log.v("a13","a13");
      }
      catch (Exception e)
      { 
          Log.v("Error in insert() definition FileEvent.java : ",e.toString());
      }
      }
  
  
  protected void onListItemClick(ListView l, View v, int position, long id) {
  
  //  try{
      Log.v("a14","a14");
  
      super.onListItemClick(l, v, position, id);
      Log.v("a15","a15");
        // ListView Clicked item index
         int itemPosition     = position;
         Log.v("a16","a16");
        // ListView Clicked item value
         String  itemValue    = (String) l.getItemAtPosition(position);
         Log.v("a17","a17");
       //  content.setText("Click : \n  Position :"+itemPosition+"  \n  ListItem : " +itemValue);
         String personname = itemValue;
         Log.v("a18","a18");
         try
         {
             System.out.println("paths in FileEvent : "+filename);
             info.insert(filename,personname);
             Log.v("a19","a19");
         }
         catch(Exception e)
         {
             Log.v("a20","a20");
             e.printStackTrace();
             Log.v("a21","a21");
         }
  
         Log.v("a22","a22");
  /*  }
      catch (Exception e)
      {
          Log.v("Error in insert() definition FileEvent.java : ",e.toString());
      }
  
  */   
  
  } 
  </code></pre>
  
  <p>And the following logcat I am getting, when I run the code - </p>
  
  <pre><code>09-27 06:37:23.269: A/FileObserver(2284): Unhandled exception in FileObserver com.example.sample_fileobserver.MyFileObserver@b11955a0
  09-27 06:37:23.269: A/FileObserver(2284): java.lang.IllegalStateException: System services not available to Activities before onCreate()
  09-27 06:37:23.269: A/FileObserver(2284):   at android.app.Activity.getSystemService(Activity.java:4492)
  09-27 06:37:23.269: A/FileObserver(2284):   at android.widget.ArrayAdapter.init(ArrayAdapter.java:310)
  09-27 06:37:23.269: A/FileObserver(2284):   at android.widget.ArrayAdapter.&lt;init&gt;(ArrayAdapter.java:128)
  09-27 06:37:23.269: A/FileObserver(2284):   at com.example.sample_fileobserver.FileEvent.insert(FileEvent.java:76)
  09-27 06:37:23.269: A/FileObserver(2284):   at com.example.sample_fileobserver.MyFileObserver.onEvent(MyFileObserver.java:59)
  09-27 06:37:23.269: A/FileObserver(2284):   at android.os.FileObserver$ObserverThread.onEvent(FileObserver.java:125)
  09-27 06:37:23.269: A/FileObserver(2284):   at android.os.FileObserver$ObserverThread.observe(Native Method)
  09-27 06:37:23.269: A/FileObserver(2284):   at android.os.FileObserver$ObserverThread.run(FileObserver.java:88)
  </code></pre>
  
  <p>Please tell me where I made mistake.</p>
  
  <p>Thanks in advance.</p>