in Education by
I've met an unknown error while inserting data into the database. The LogCat had been display "unable to insert data", however, the code that I've used is copied from another activity (which works). weird enough, when I placed the code in the onStart() method, it works. but when I placed into my onClick(), it failed. onStart(): <- not sure whether it's related to the error @Override public void onStart() { super.onStart(); dbopener = new DB_Route_ListOpener(this); try { dbopener.createDatabase(); } catch (IOException ioe) { throw new Error("Unable to create database"); }//create database try { dbopener.openDatabase(); }catch(SQLException sqle){ throw sqle; }//open database // Configure the listview routeItems = new ArrayList<String>(dbopener.selectData(new String [] {"RouteName"}, null, null, null, null, null)); routeListAdapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1,routeItems); routeListItem = (ListView)this.findViewById(R.id.mlt_route_list_route); routeListItem.setAdapter(routeListAdapter); routeListItem.setChoiceMode(ListView.CHOICE_MODE_SINGLE); dbopener.close(); }//onStart onClick(): @Override public void onClick(View v) { // TODO Auto-generated method stub if (v == findViewById(R.id.mlt_route_btn_addroute))//add { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setCancelable(false); builder.setMessage("Add name ?"); builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub dialog.dismiss(); ContentValues cv = new ContentValues(); cv.put("RouteName", "test"); dbopener.insertData(null, cv); } });//clear all data builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub dialog.cancel(); } });//negative builder.create().show(); }//if my insert query: public void insertData (String nullColumnHack, ContentValues values) { try { myDatabase.insert(DB_TABLE, nullColumnHack, values); } catch (Exception e) { Log.e("Error :","unable to insert data"); }//catch }//insertData JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
You need to set the dbopener as a global variable and move dbopener.close(); from OnStart() to OnDestroy() since you closed the DB before you insert the data

Related questions

0 votes
    I've met an unknown error while inserting data into the database. The LogCat had been display "unable to insert data", ... I placed into my onClick(), it failed. onStart():...
asked Feb 5, 2022 in Education by JackTerrance
0 votes
    Which one of the following provides the ability to query information from the database and to insert tuples ... Database Interview Questions and Answers for Freshers and Experience...
asked Oct 11, 2021 in Education by JackTerrance
0 votes
    I would like to take a list of names (e.g. john, mary, paul) and create a SQLite "select" ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 7, 2022 in Education by JackTerrance
0 votes
    I need a standard deviation function in SQLite. I have found one here: http://www.sqlite.org/contrib ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 26, 2022 in Education by JackTerrance
0 votes
    I'm using beautifulsoup and selenium to scrape some data in python. Here is my code which I run ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 7, 2022 in Education by JackTerrance
0 votes
    I'm using beautifulsoup and selenium to scrape some data in python. Here is my code which I run ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 7, 2022 in Education by JackTerrance
0 votes
    when you insert an excel file into a word document the data is _______ a) hyperlinked b)linked c)embedded d)placed ina word document Select the correct answer from above options...
asked Dec 13, 2021 in Education by JackTerrance
0 votes
    We have to create a kiosk mode android app. The app is ready, we need only to set kiosk mode. ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 24, 2022 in Education by JackTerrance
0 votes
    I am seeking an Android solution to calculate the distance to an object and then determine the size (height ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 2, 2022 in Education by JackTerrance
0 votes
    I don't seem to be able to close the OledbDataReader object after reading data from it. Here is ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 17, 2022 in Education by JackTerrance
0 votes
    I don't seem to be able to close the OledbDataReader object after reading data from it. Here is ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 17, 2022 in Education by JackTerrance
0 votes
    I don't seem to be able to close the OledbDataReader object after reading data from it. Here is ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 16, 2022 in Education by JackTerrance
0 votes
    I don't seem to be able to close the OledbDataReader object after reading data from it. Here is ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 16, 2022 in Education by JackTerrance
0 votes
    As it currently stands, this question is not a good fit for our Q&A format. We expect answers to ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jan 13, 2022 in Education by JackTerrance
0 votes
    how can you insert some other html text file into your one html file? write the tag used for this purpose? Select the correct answer from above options...
asked Nov 28, 2021 in Education by JackTerrance
...