[android-developers] Implementing database in Android
Hello.. In the following code I am trying to insert data from the application to database on save button but It is aborting the application after the execution of 2nd toast (Printing Check2). Please guide where I am wrong. save.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub //Fetching data from controls to variable!! EditText text1 = (EditText) findViewById(R.id.edittext1); EditText text2 = (EditText) findViewById(R.id.edittext2); Spinner text3 = (Spinner) findViewById(R.id.spinner1); EditText text4 = (EditText) findViewById(R.id.edittext3); Spinner text5 = (Spinner) findViewById(R.id.spinner2); Toast.makeText(MyContactsActivity.this, check1, Toast.LENGTH_LONG).show(); str_name = text1.getText().toString(); str_num = text2.getText().toString(); str_ntype = text3.getSelectedItem().toString(); str_email = text4.getText().toString(); str_etype = text5.getSelectedItem().toString(); int_num = Integer.parseInt(str_num); Toast.makeText(MyContactsActivity.this, Check2, Toast.LENGTH_LONG).show(); //Creating or Opening (Existing) Database!! SQLiteDatabase db = openOrCreateDatabase(dbName, MODE_PRIVATE, null); Log.d(Database, Created); //Creating Table!! db.execSQL( CREATE TABLE IF NOT EXISTS +tblName+ ( +uName+ TEXT PRIMARY KEY, +uNum+ INTEGER, +NoType+ TEXT, +uEmail+TEXT, +eType+TEXT)); Log.d(Table, Created); //Inserting data into table!! db.execSQL( INSERT INTO +tblName+ VALUES(' +str_name+ ', +int_num+ ,' +str_ntype+ ',' +str_email+ ',' +str_etype+ ')); Log.d(Data of +str_name, Inserted); text1.setText(); text2.setText(); text3.setId(0); text4.setText(); text5.setId(0); Toast.makeText(MyContactsActivity.this, Data of +str_name+: Inserted, Toast.LENGTH_LONG).show(); } }); -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
Re: [android-developers] Implementing database in Android
Use adb logcat, DDMS, or the DDMS perspective in Eclipse to examine LogCat and look at the stack trace associated with your abort. On Thu, Sep 22, 2011 at 1:28 PM, Gaurav Srivastava gaurav.srivastava0...@gmail.com wrote: Hello.. In the following code I am trying to insert data from the application to database on save button but It is aborting the application after the execution of 2nd toast (Printing Check2). Please guide where I am wrong. save.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub //Fetching data from controls to variable!! EditText text1 = (EditText) findViewById(R.id.edittext1); EditText text2 = (EditText) findViewById(R.id.edittext2); Spinner text3 = (Spinner) findViewById(R.id.spinner1); EditText text4 = (EditText) findViewById(R.id.edittext3); Spinner text5 = (Spinner) findViewById(R.id.spinner2); Toast.makeText(MyContactsActivity.this, check1, Toast.LENGTH_LONG).show(); str_name = text1.getText().toString(); str_num = text2.getText().toString(); str_ntype = text3.getSelectedItem().toString(); str_email = text4.getText().toString(); str_etype = text5.getSelectedItem().toString(); int_num = Integer.parseInt(str_num); Toast.makeText(MyContactsActivity.this, Check2, Toast.LENGTH_LONG).show(); //Creating or Opening (Existing) Database!! SQLiteDatabase db = openOrCreateDatabase(dbName, MODE_PRIVATE, null); Log.d(Database, Created); //Creating Table!! db.execSQL( CREATE TABLE IF NOT EXISTS +tblName+ ( +uName+ TEXT PRIMARY KEY, +uNum+ INTEGER, +NoType+ TEXT, +uEmail+TEXT, +eType+TEXT)); Log.d(Table, Created); //Inserting data into table!! db.execSQL( INSERT INTO +tblName+ VALUES(' +str_name+ ', +int_num+ ,' +str_ntype+ ',' +str_email+ ',' +str_etype+ ')); Log.d(Data of +str_name, Inserted); text1.setText(); text2.setText(); text3.setId(0); text4.setText(); text5.setId(0); Toast.makeText(MyContactsActivity.this, Data of +str_name+: Inserted, Toast.LENGTH_LONG).show(); } }); -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -- Mark Murphy (a Commons Guy) http://commonsware.com | http://github.com/commonsguy http://commonsware.com/blog | http://twitter.com/commonsguy Warescription: Three Android Books, Plus Updates, One Low Price! -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
Re: [android-developers] Implementing database in Android
On Sun, Sep 18, 2011 at 10:40 PM, Gaurav Srivastava gaurav.srivastava0...@gmail.com wrote: so anyone is having a demo or sample application which is running properly and will be useful for me? You of course checked the documentation and did some simple Google search, yes? - TreKing http://sites.google.com/site/rezmobileapps/treking - Chicago transit tracking app for Android-powered devices -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
Re: [android-developers] Implementing database in Android
Thanks. Devendran. -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Implementing database in Android
Hello, I want to develop an application in Android which needs to implement database. so anyone is having a demo or sample application which is running properly and will be useful for me? Please reply. -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en