-1
幫助!我將地理位置數據從android傳輸到數據庫。給出錯誤消息。錯誤:(45,46)錯誤:無法找到符號方法getWritableDatabase()。幫幫我! enter image description hereSQLiteDatabase dbm = this.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();
}
} }); } }
你能舉個例子嗎?我不太明白。 –