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 [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to