mercredi 30 décembre 2015

Data Insertion in table giving error in android

I'm retrieving some data from different Views and then inserting the data into a table. But whenever I press the insert button the application crashes and says "Application stopped responding". I have spent like 2 hours on this and I'm completely stuck here. This is my first application using Sqlite in android.

This is my Java code

 btnInsert.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            getValues();
            if(b.getString("insTableVal").equals("Donor")){
                MainActivity.db.execSQL("INSERT INTO Donor VALUES("+IdVal+","+NameVal+","+AgeVal+","+GenderVal+","+BGVal+");");
            }
            else if(b.getString("insTableVal").equals("Recipient")){
                MainActivity.db.execSQL("INSERT INTO Recipient VALUES("+IdVal+","+NameVal+","+AgeVal+","+GenderVal+","+BGVal+");");
            }
        }
    });

This is the logcat

12-31 06:50:00.038 13562-13562/com.example.bilalrafique.bloodbankmanagementsystem E/AndroidRuntime: FATAL EXCEPTION: main
                                                                                                Process: com.example.bilalrafique.bloodbankmanagementsystem, PID: 13562
                                                                                                java.lang.NullPointerException
                                                                                                    at com.example.bilalrafique.bloodbankmanagementsystem.DnRInsertion$1.onClick(DnRInsertion.java:34)
                                                                                                    at android.view.View.performClick(View.java:4466)
                                                                                                    at android.view.View$PerformClick.run(View.java:18537)
                                                                                                    at android.os.Handler.handleCallback(Handler.java:733)
                                                                                                    at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                                                    at android.os.Looper.loop(Looper.java:136)
                                                                                                    at android.app.ActivityThread.main(ActivityThread.java:5102)
                                                                                                    at java.lang.reflect.Method.invokeNative(Native Method)
                                                                                                    at java.lang.reflect.Method.invoke(Method.java:515)
                                                                                                    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
                                                                                                    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
                                                                                                    at dalvik.system.NativeStart.main(Native Method)

Where is the Null pointer Exception occuring. I can't figure out. Thanks in Advance.

Aucun commentaire:

Enregistrer un commentaire