title: unable to open the local database in android
body: <p>I have service in android,from that service i started an activity.I called the method inside the activity from service.In that method,i open the database and tried to insert the values.Without using database,its working fine.But my app getting force closed when i used database</p>
  
  <p>plugin(java file)-->service-->Activity(here i try to insert the data in database)</p>
  
  <p><strong>service.java</strong></p>
  
  <pre><code>public class MyService extends Service 
  {
      @Override
      public IBinder onBind(Intent intent) 
      {
          return null;
      }
  
      @Override
      public void onCreate() 
      {
          Log.d(TAG, "onCreate");
      }
  
      @Override
      public void onDestroy() 
      {
          Log.d(TAG, "onDestroy");
      }
  
      public void onStart(Intent intent, int startid) 
      {
          Timer mTimer = new Timer(user);
          mTimer.scheduleAtFixedRate(new mainTask(), 5000,60000);//1 hour=3600 s
  
      }
  
      private class mainTask extends TimerTask 
      { 
          public void run() 
          {
              toastHandler.sendEmptyMessage(0);
          }
      }  
  
  
      private final Handler toastHandler = new Handler() 
      {
          public void handleMessage(Message msg) 
          {
               StorageHelper s=new StorageHelper();
               String a= s.UpdateValues(userid);
          }
      };    
  }
  </code></pre>
  
  <p><strong>Activity.java</strong></p>
  
  <pre><code>public class StorageHelper extends Activity
  {
      @Override
      public void onCreate(Bundle savedInstanceState) 
      {
          super.onCreate(savedInstanceState); 
      }
  
      public  String UpdateValues(int userid)
      {
          try {
              DBAdapter1 database=new DBAdapter1(this);
              database.open();
              long id=database.insert(71,4,"yes");
              database.close();
          } catch (SQLException e) {
  
          }
          return "success";
      }
  }
  </code></pre>
  
  <p><strong>Note</strong>
  when i open the database in oncreate its working,But inside the updatavalues() database cannot open to insert.</p>
  
  <pre><code>try {
      DBAdapter1 database=new DBAdapter1(this);
      database.open();
      long id=database.insert(71,4,"yes");
      database.close();
  } catch (SQLException e) {
  
  }
  </code></pre>
  
  <p>i got two type of force close</p>
  
  <p>Error number 1</p>
  
  <pre><code>07-09 15:16:27.859: E/AndroidRuntime(1211): FATAL EXCEPTION: main
  07-09 15:16:27.859: E/AndroidRuntime(1211): java.lang.NullPointerException
  07-09 15:16:27.859: E/AndroidRuntime(1211):     at android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:203)
  07-09 15:16:27.859: E/AndroidRuntime(1211):     at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:98)
  07-09 15:16:27.859: E/AndroidRuntime(1211):     at com.app.mobilyzer.DBAdapter1.open(DBAdapter1.java:68)
  07-09 15:16:27.859: E/AndroidRuntime(1211):     at com.app.mobilyzer.StorageHelper.UpdateValues(StorageHelper.java:33)
  07-09 15:16:27.859: E/AndroidRuntime(1211):     at com.app.mobilyzer.MyService$1.handleMessage(MyService.java:121)
  07-09 15:16:27.859: E/AndroidRuntime(1211):     at android.os.Handler.dispatchMessage(Handler.java:99)
  07-09 15:16:27.859: E/AndroidRuntime(1211):     at android.os.Looper.loop(Looper.java:123)
  07-09 15:16:27.859: E/AndroidRuntime(1211):     at android.app.ActivityThread.main(ActivityThread.java:4627)
  07-09 15:16:27.859: E/AndroidRuntime(1211):     at java.lang.reflect.Method.invokeNative(Native Method)
  07-09 15:16:27.859: E/AndroidRuntime(1211):     at java.lang.reflect.Method.invoke(Method.java:521)
  07-09 15:16:27.859: E/AndroidRuntime(1211):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
  07-09 15:16:27.859: E/AndroidRuntime(1211):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
  07-09 15:16:27.859: E/AndroidRuntime(1211):     at dalvik.system.NativeStart.main(Native Method)
  </code></pre>
  
  <p>Error number 2</p>
  
  <pre><code>07-09 15:16:36.889: E/AndroidRuntime(1237): FATAL EXCEPTION: main
  07-09 15:16:36.889: E/AndroidRuntime(1237): java.lang.RuntimeException: Unable to start service com.app.mobilyzer.MyService@44fc6280 with null: java.lang.NullPointerException
  07-09 15:16:36.889: E/AndroidRuntime(1237):     at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3063)
  07-09 15:16:36.889: E/AndroidRuntime(1237):     at android.app.ActivityThread.access$3600(ActivityThread.java:125)
  07-09 15:16:36.889: E/AndroidRuntime(1237):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2096)
  07-09 15:16:36.889: E/AndroidRuntime(1237):     at android.os.Handler.dispatchMessage(Handler.java:99)
  07-09 15:16:36.889: E/AndroidRuntime(1237):     at android.os.Looper.loop(Looper.java:123)
  07-09 15:16:36.889: E/AndroidRuntime(1237):     at android.app.ActivityThread.main(ActivityThread.java:4627)
  07-09 15:16:36.889: E/AndroidRuntime(1237):     at java.lang.reflect.Method.invokeNative(Native Method)
  07-09 15:16:36.889: E/AndroidRuntime(1237):     at java.lang.reflect.Method.invoke(Method.java:521)
  07-09 15:16:36.889: E/AndroidRuntime(1237):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
  07-09 15:16:36.889: E/AndroidRuntime(1237):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
  07-09 15:16:36.889: E/AndroidRuntime(1237):     at dalvik.system.NativeStart.main(Native Method)
  07-09 15:16:36.889: E/AndroidRuntime(1237): Caused by: java.lang.NullPointerException
  07-09 15:16:36.889: E/AndroidRuntime(1237):     at com.app.mobilyzer.MyService.onStart(MyService.java:81)
  07-09 15:16:36.889: E/AndroidRuntime(1237):     at android.app.Service.onStartCommand(Service.java:420)
  07-09 15:16:36.889: E/AndroidRuntime(1237):     at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3053)
  07-09 15:16:36.889: E/AndroidRuntime(1237):     ... 10 more
  </code></pre>