帮助!我正在将地理位置数据从 android 传输到数据库。给出错误信息。错误:(45, 46) 错误:找不到符号方法getWritableDatabase()。帮助! 在此处输入图像描述
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();
}
} }); } }