{"id":3200,"date":"2014-03-20T02:40:21","date_gmt":"2014-03-20T02:40:21","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/20\/error-in-database-collection-of-common-programming-errors\/"},"modified":"2014-03-20T02:40:21","modified_gmt":"2014-03-20T02:40:21","slug":"error-in-database-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/20\/error-in-database-collection-of-common-programming-errors\/","title":{"rendered":"Error in database-Collection of common programming errors"},"content":{"rendered":"<p>Please help find the problem in my code. I&#8217;m trying to check if the user entered a valid email address and if its already existing. I already trap if the user entered invalid email address through some formatting, I already checked if the email is existing and my problem is whenever the user entered new and valid email address, my application crashed. Here&#8217;s my code:<\/p>\n<pre><code>else if (!Email.equals(\"\"))\n{\n    if(Email.equals(storedEmail))   \/\/Check if the email address already exist\n       {\n           Toast.makeText(getApplicationContext(), \"Email address already exist.\",Toast.LENGTH_LONG).show();\n       }\n\n\n    else if (!matcherObj.matches()) \/\/it will check if the user enter valid email\n      {\n        Toast.makeText(getApplicationContext(), \"Invalid email address.\",Toast.LENGTH_LONG).show();\n        txtEmail.setText(\"\");\n      }\n    else \/\/ if the email address is not existing and is valid it will save to the database\n      {\n        db.Register(newPatientInfo(Fname,Mname,Lname,Suffix,Birthday,Homeno,MobileNo,Email,Brgy,Province,CityMun,Zip,CFname,CLname,DClinic,DClinicAdd));\n        Toast.makeText(getApplicationContext(),\"Saved!\", Toast.LENGTH_LONG).show();\n        Clear();\n      }\n<\/code><\/pre>\n<p>}<\/p>\n<p>here is my code in my databasehandler<\/p>\n<pre><code>public String Patient_Emailexist(String p_email)                \n{               \n  SQLiteDatabase db = this.getReadableDatabase();               \n  Cursor c = db.query(TABLE_PATIENT, null, PATIENT_EMAIL + \"=?\", new String[]{String.valueOf(p_email)},null, null, null);                                               \n    if (c == null)              \n      {                        \n        c.moveToFirst();                                    \n      }                 \n         c.moveToFirst();               \n         String patient_email = c.getString(c.getColumnIndex(PATIENT_EMAIL));               \n         return patient_email;  \n}\n<\/code><\/pre>\n<p>My application crash whenever I enter a valid and new email address that is supposed to be save in the database. Thanks in advance!<\/p>\n<p>errors found<\/p>\n<p>05-17 10:27:17.410: E\/AndroidRuntime(678): FATAL EXCEPTION: main 05-17 10:27:17.410: E\/AndroidRuntime(678): android.database.CursorIndexOutOfBoundsException: Index 0 requested, with a size of 0 05-17 10:27:17.410: E\/AndroidRuntime(678): at android.database.AbstractCursor.checkPosition(AbstractCursor.java:418) 05-17 10:27:17.410: E\/AndroidRuntime(678): at android.database.AbstractWindowedCursor.checkPosition(AbstractWindowedCursor.java:136) 05-17 10:27:17.410: E\/AndroidRuntime(678): at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:50) 05-17 10:27:17.410: E\/AndroidRuntime(678): at com.example.palsproject.DatabaseHandler.Patient_Emailexist(DatabaseHandler.java:353) 05-17 10:27:17.410: E\/AndroidRuntime(678): at com.example.palsproject.PatientRegistration$1.onClick(PatientRegistration.java:95) 05-17 10:27:17.410: E\/AndroidRuntime(678): at android.view.View.performClick(View.java:4084) 05-17 10:27:17.410: E\/AndroidRuntime(678): at android.view.View$PerformClick.run(View.java:16966) 05-17 10:27:17.410: E\/AndroidRuntime(678): at android.os.Handler.handleCallback(Handler.java:615) 05-17 10:27:17.410: E\/AndroidRuntime(678): at android.os.Handler.dispatchMessage(Handler.java:92) 05-17 10:27:17.410: E\/AndroidRuntime(678): at android.os.Looper.loop(Looper.java:137) 05-17 10:27:17.410: E\/AndroidRuntime(678): at android.app.ActivityThread.main(ActivityThread.java:4745) 05-17 10:27:17.410: E\/AndroidRuntime(678): at java.lang.reflect.Method.invokeNative(Native Method) 05-17 10:27:17.410: E\/AndroidRuntime(678): at java.lang.reflect.Method.invoke(Method.java:511) 05-17 10:27:17.410: E\/AndroidRuntime(678): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786) 05-17 10:27:17.410: E\/AndroidRuntime(678): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 05-17 10:27:17.410: E\/AndroidRuntime(678): at dalvik.system.NativeStart.main(Native Method)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Please help find the problem in my code. I&#8217;m trying to check if the user entered a valid email address and if its already existing. I already trap if the user entered invalid email address through some formatting, I already checked if the email is existing and my problem is whenever the user entered new [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-3200","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/3200","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=3200"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/3200\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=3200"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=3200"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=3200"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}