【发布时间】:2020-12-24 19:46:25
【问题描述】:
我正在获取一个位置的纬度和经度信息并将它们添加到 SQLite。看起来我创建数据库没有问题,但我的插入不起作用。这是我的代码:
private GoogleMap mMap;
Button button;
double _lat,_lon;
Intent intent;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
intent = getIntent();
_lat = intent.getDoubleExtra("yenie",0);
_lon = intent.getDoubleExtra("yenib",0);
button = findViewById(R.id.kaydet);
SQLiteDatabase database = this.openOrCreateDatabase("Konumlar",MODE_PRIVATE,null);
database.execSQL("CREATE TABLE IF NOT EXISTS knm (lat DOUBLE,lon DOUBLE)");
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try{
database.execSQL("INSERT INTO knm (lat,lon) VALUES (_lat,_lon)");
Toast.makeText(getApplicationContext(),"sa",Toast.LENGTH_LONG);
}
catch (Exception e){
}
}
});
}
据我调试了解,在 onClick() 方法中,插入失败并被捕获。我的问题可能是什么?提前致谢。
【问题讨论】:
-
LogException正在被抓到,以获取有关它的线索..
标签: java android sqlite android-sqlite