嗨,我開始學習android我試過這段代碼。它顯示無法打開數據庫,以及我的路徑是否正確,如果它是錯誤的我如何創建。請誰能幫助無法打開數據庫android sqlite
public class Sql3Activity extends Activity
{
public static final String TAG = "DatabaseHelper";
public static final String DATABASE_NAME = "mydb";
public static final String TRACKS_TABLE = "tracks";
public static final String TRACK_INFO_TABLE = "track_info";
public final String TRACKS_TABLE_CREATE = "create table " + TRACKS_TABLE
+ " (_id integer primary key autoincrement, title text not null, description text null, created_at date not null);";
public static final String TRACK_INFO_TABLE_CREATE = "create table "
+ TRACK_INFO_TABLE
+ " (_id integer primary key autoincrement, track_id integer not null, latitude real not null, longitude real not null, altitude real not null, created_at date not null);";
public SQLiteDatabase database;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sql3);
final String DATABASE_FILE_PATH = Environment.getExternalStorageDirectory()+"/test";
Toast.makeText(Sql3Activity .this,DATABASE_FILE_PATH,Toast.LENGTH_LONG).show();
try{
database = SQLiteDatabase.openDatabase(DATABASE_FILE_PATH + File.separator + DATABASE_NAME, null, SQLiteDatabase.OPEN_READWRITE);
Toast.makeText(Sql3Activity .this,"Database Open",Toast.LENGTH_LONG).show();
}catch(Exception e)
{
Toast.makeText(Sql3Activity .this,"ERROR"+e,Toast.LENGTH_LONG).show();
}
顯示異常的堆棧跟蹤'e' – Houssni
使用SQLiteOpenHelper與數據庫 –
表演工作你的日誌貓錯誤.. –