6
私はandroid javaプロジェクトで複数のSQLiteデータベースを使用しています。最初のもの(ログイン用)は正常に動作し、次のコードを使用して接続を終了します。しかし、次のページでは別のデータベースを使用する関数を呼び出していますが、新しいデータベースではなく最初のデータベースを参照しているようです。このエラーが発生しています:Android:SQLite間違ったデータベースを使用
09-14 13:18:01.990: I/SqliteDatabaseCpp(10035): sqlite returned: error code = 1, msg = no such table:
NextID, db=/mnt/extSdCard/DirectEnquiries/AuditingData/Static/Users
これは正しいですが、NextIDはユーザーではありません。ここで
ユーザーのテーブルを使用してログインページのコードは次のとおりです。
if(String.valueOf(loginCount).equals("2")) {
File dbfile = new File(Global.StaticDB + "/Users");
SQLiteDatabase db = SQLiteDatabase.openOrCreateDatabase(dbfile, null);
Cursor c = db.rawQuery("SELECT UserID from Users where UserID like '" + txtUsername.getText().toString().trim() + "' AND Password like '" + txtPassword.getText().toString().trim() + "'", null);
c.moveToFirst();
if(c.getCount() > 0) {
Global.Username = c.getString(c.getColumnIndex("UserID"));
Global.currentDB = spnLocation.getSelectedItem().toString();
Global.currentDBfull = Global.sctArea + Global.currentDB;
db.close();
Context context = getApplicationContext();
CharSequence text = "Logged In";
int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(context, text, duration);
toast.show();
Intent ShowMainPage = new Intent(view.getContext(), MainPage.class);
startActivityForResult(ShowMainPage, 0);
}
次のページが、この使用している:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_page);
TextView txt = (TextView) findViewById(R.id.textView1);
txt.setText(Global.Username);
TextView dbtxt = (TextView) findViewById(R.id.txtDB);
dbtxt.setText(Functions.getNextID("StationObjects"));
}
を関数は次のとおりです。
public static int getNextID(String tablename) {
Log.e("Current DB is: ", Global.currentDBfull);
File dbfile = new File(Global.currentDBfull);
SQLiteDatabase dbF = SQLiteDatabase.openOrCreateDatabase(dbfile, null);
int rtnID=(int)DatabaseUtils.longForQuery(dbF,"Select NxtNumber from NextID where NxtTable like '" + tablename + "'",null);
rtnID += 1;
//db.rawQuery("update NextID set NxtNumber = '" + rtnID + "' where NxtTable like 'StationObjects'", null);
dbF.close();
return rtnID;
}
最初のデータベースではなく2番目のデータベースが使用されていることを確認するにはどうすればよいですか? トム
あなたはそのログインデータベース上にカーソルを閉じたのですか? – jnthnjns
ちょうど最初のサブのカーソルを閉じようとしましたが、同じエラー – TMB87
あなたはlogcatの多くを投稿しませんでした。 「Current DB is:」というメッセージ、例外などを確認できますか?また、Global.sctAreaとは何ですか?(c.getCount()> 0)がfalseの場合はどうなりますか?あなたは多くの情報を隠している(私はそれが単純であることを知っているが、それはあまり役に立たない...) –