title: android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:252) nullpointerexception
body: <p>I'm trying to add current locations latitude and longitude in <code>Sqlite Database</code>.
  But when i open my activity it crashes by saying <code>android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:252)</code>
  I can't understand what is the problem.
  My Code is</p>
  
  <pre><code>protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main_page);
  
      try {
          setUpMapIfNeeded();
      }catch (Exception e){
          e.printStackTrace();
          Toast.makeText(MainPage.this, "Google Play Services Out of Date. Please Update.", Toast.LENGTH_SHORT).show();
      }
  
      googleMap.setMyLocationEnabled(true);
      googleMap.getUiSettings().setMyLocationButtonEnabled(true);
      googleMap.getUiSettings().setMapToolbarEnabled(false);
      googleMap.getUiSettings().setZoomControlsEnabled(true);
  
      locMan =(LocationManager)getSystemService(Context.LOCATION_SERVICE);
      locMan.requestLocationUpdates(LocationManager.GPS_PROVIDER,0,0,this);
  
      Button btnRecord=(Button)findViewById(R.id.button);
      btnRecord.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              LocationManager locationManager=(LocationManager)getSystemService(Context.LOCATION_SERVICE);
              locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, new LocationListener() {
                  @Override
                  public void onLocationChanged(Location location) {
                      LatLng latLng=new LatLng(location.getLatitude(),location.getLongitude());
                      double latitude=location.getLatitude();
                      double longitude=location.getLongitude();
                      ContentValues cv=new ContentValues();
                      try{
  
                          DatabaseHelper databaseHelper=new DatabaseHelper(MainPage.this);
                          SQLiteDatabase db=databaseHelper.getReadableDatabase();
  
                          cv.put("latitude",latitude);
                          cv.put("longitude",longitude);
  
                          long insert=db.insert("latLngTable",null,cv);
  
                          if (insert!=-1){
                              Toast.makeText(MainPage.this,"Datas Inserted",Toast.LENGTH_SHORT).show();
                          }else {
                              Toast.makeText(MainPage.this,"Insertion Failed",Toast.LENGTH_SHORT).show();
                          }
  
                      }catch (SQLiteException e){
                          Toast.makeText(MainPage.this,e.getMessage(),Toast.LENGTH_SHORT).show();
                      }
                  }
  
                  @Override
                  public void onStatusChanged(String provider, int status, Bundle extras) {
  
                  }
  
                  @Override
                  public void onProviderEnabled(String provider) {
  
                  }
  
                  @Override
                  public void onProviderDisabled(String provider) {
  
                  }
              });
          }
      });
  
  }
  
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
      getMenuInflater().inflate(R.menu.menu_main_page, menu);
      return true;
  }
  
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
      int id = item.getItemId();
  
      if (id == R.id.viewLocations) {
          Intent i=new Intent(MainPage.this,LocationsList.class);
          startActivity(i);
          return true;
      }
  
      return super.onOptionsItemSelected(item);
  }
  
  @Override
  protected void onResume() {
      super.onResume();
      setUpMapIfNeeded();
  }
  
  private void setUpMapIfNeeded() {
      if (googleMap == null) {
          googleMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map))
                  .getMap();
          if (googleMap != null) {
              setUpMap();
          }
      }
  }
  
  private void setUpMap() {
      //googleMap.addMarker(new MarkerOptions().position(new LatLng(latitude, longitude)).icon(bitmapDescriptor).title(locality).snippet(""));
  }
  
  @Override
  public void onLocationChanged(Location location) {
      LatLng latLng1 = new LatLng(location.getLatitude(), location.getLongitude());
      CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(latLng1, 16.5f);
      googleMap.animateCamera(cameraUpdate);
      locMan.removeUpdates(this);
  }
  
  @Override
  public void onStatusChanged(String provider, int status, Bundle extras) {
  
  }
  
  @Override
  public void onProviderEnabled(String provider) {
  
  }
  
  @Override
  public void onProviderDisabled(String provider) {
  
  }
  </code></pre>
  
  <p>I have used <code>SQLiteOpenHelper</code> to create my database.
  I have previously used them without error but now I'm getting this error.
  Anyone please help.</p>
  
  <p>My <code>SQLiteOpenHelper</code> is</p>
  
  <pre><code>public class DatabaseHelper extends SQLiteOpenHelper {
  public static final String db_name="latLngDB";
  public static final int version=1;
  Context context;
  
  public DatabaseHelper(Context context){
      super(context,db_name,null,version);
  }
  
  @Override
  public void onCreate(SQLiteDatabase db){
  
      db.execSQL("create table latLngTable(_id INTEGER PRIMARY KEY AUTOINCREMENT,latitude integer,longitude integer)");
      Toast.makeText(context,"Database Created",Toast.LENGTH_SHORT).show();
  }
  
  @Override
  public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion){
      if (oldVersion&gt;=newVersion)
  
          return;
  
      if (oldVersion==1){
  
          Log.d("New Version","Data's can be Upgraded");
  
      }
  
      Log.d("Sample Data", "onUpgrade:" + newVersion);
  
  }
  </code></pre>
  
  <p>}</p>
  
  <blockquote>
    <p>LogCat is</p>
  </blockquote>
  
  <pre><code>07-22 15:31:17.652  14125-14125/? E/AndroidRuntime﹕ FATAL EXCEPTION: main
  Process: com.realtech.latlngrecorder, PID: 14125
  java.lang.NullPointerException
          at android.widget.Toast.&lt;init&gt;(Toast.java:93)
          at android.widget.Toast.makeText(Toast.java:241)
          at com.realtech.latlngrecorder.DatabaseHelper.onCreate(DatabaseHelper.java:22)
          at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:252)
          at android.database.sqlite.SQLiteOpenHelper.getReadableDatabase(SQLiteOpenHelper.java:188)
          at com.realtech.latlngrecorder.MainPage$1$1.onLocationChanged(MainPage.java:67)
          at android.location.LocationManager$ListenerTransport._handleMessage(LocationManager.java:279)
          at android.location.LocationManager$ListenerTransport.access$000(LocationManager.java:208)
          at android.location.LocationManager$ListenerTransport$1.handleMessage(LocationManager.java:224)
          at android.os.Handler.dispatchMessage(Handler.java:110)
          at android.os.Looper.loop(Looper.java:193)
          at android.app.ActivityThread.main(ActivityThread.java:5292)
          at java.lang.reflect.Method.invokeNative(Native Method)
          at java.lang.reflect.Method.invoke(Method.java:515)
          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:824)
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:640)
          at dalvik.system.NativeStart.main(Native Method)
  </code></pre>