-1

Help! I'm transferring geolocation data from android to the database. Gives an error message. Error: (45, 46) error: can not find symbol method getWritableDatabase (). Help! enter image description here

public class AndroidGPSTrackingActivity extends Activity {

    Button btnShowLocation;

    // GPSTracker class
    GPSTracker gps;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        btnShowLocation.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View arg0) {
                // create class object
                gps = new GPSTracker(AndroidGPSTrackingActivity.this);

                // check if GPS enabled
                if(gps.canGetLocation()){

                    double latitude = gps.getLatitude();
                    double longitude = gps.getLongitude();
                    SQLiteDatabase dbm = this.getWritableDatabase();
                    ContentValues cv = new ContentValues();


                    cv.put("LAT_G",
                            gps.getLatitude());

                    cv.put("LANG",  gps.getLongitude());

                    boolean result = dbm.insert("table name", cv);


                    Toast.makeText(getApplicationContext(), "Your Location is - \nLat: " + latitude + "\nLong: " + longitude, Toast.LENGTH_LONG).show();
                }else{
                    // can't get location
                    // GPS or Network is not enabled
                    // Ask user to enable GPS/network in settings
                    gps.showSettingsAlert();
                } 
     }  }); }  }
laalto
  • 150,114
  • 66
  • 286
  • 303
Alex Nikonov
  • 1
  • 1
  • 3

1 Answers1

0

getWritableDatabase() is a method in SQLiteOpenHelper. this in your code refers to the View.OnClickListener anon inner class instance that is not a SQLiteOpenHelper nor has such method in it.

You'd need to implement your own class extending SQLiteOpenHelper, instantiate it, and then call getWritableDatabase() on the instance to obtain an SQLiteDatabase to work with.

laalto
  • 150,114
  • 66
  • 286
  • 303