我想與我的應用程序建立數據庫連接。它爲訪客提供了允許和拒絕按鈕。每當我嘗試調用數據庫類的操作時,我的app force都會關閉。例如,當我單擊「允許」按鈕時,我希望應用程序將訪問者ID,日期和字符串響應存儲在數據庫中。 以下是在我的按鈕在MainActivity代碼:Android應用程序強制關閉數據庫連接嘗試
//databaseVisitor VisDB = new databaseVisitor (this);
//VisitorDatabase VDB = new VisitorDatabase();
//Defining the actions of the Allow Button
Button.OnClickListener allowListener = new Button.OnClickListener(){
public void onClick(View arg0) {
// TODO Auto-generated method stub
Toast allowToast = Toast.makeText(MainActivity.this, R.string.toastYes, Toast.LENGTH_LONG);
allowToast.show();
//Log.d("Insert Log: ", "Inserting add log..");
//count = VisDB.getVisitorCount();
response = "Access Granted";
//dt = date.getDate();
//VisDB.addVisitor(new VisitorDatabase(count+1, dt, response));
}
};
發佈您的LogCat錯誤,以便我們可以看到發生了什麼。 – Sam
嗨,@Marcin捷克第一評論! – Ascension
@Sam:這些是我得到的Logcat錯誤。 12-03 13:03:57.467:E/AndroidRuntime(283):致命異常:主 12-03 13:03:57.467:E/AndroidRuntime(283):java.lang.RuntimeException:無法啓動活動ComponentInfo { com.example.imagefetch/com.example.imagefetch.MainActivity}:java.lang.NullPointerException 12-03 13:03:57.467:E/AndroidRuntime(283):\t at android.app.ActivityThread.performLaunchActivity(ActivityThread.java :2663) 12-03 13:03:57.467:E/AndroidRuntime(283):\t at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679) – pointNclick