title: Data Insertion in table giving error in android
body: <p>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. </p>
  
  <p>I have about 10 classes and different variables are coming from different classes so cannot post the complete java code. <strong>Here is the java code causing the problem, logcat shows error at the execSQL statement within the if</strong>. </p>
  
  <p><em>insTabVal</em> is an Extra that comes with the Intent and it tells in which Table to put the data, <em>MainActivity</em> is also not null and <em>db</em> is SQLite Database object which is also open. All the <em>Val variables</em> within the SQL query are the values to be inserted in the table and come from different views and they are also not null.</p>
  
  <pre><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+");");
              }
          }
      });
  </code></pre>
  
  <p>This is the logcat</p>
  
  <pre><code>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)
  </code></pre>
  
  <p>Where is the Null pointer Exception occuring. I can't figure out.</p>
  
  <p>P.S <a href="https://stackoverflow.com/questions/3988788/what-is-a-stack-trace-and-how-can-i-use-it-to-debug-my-application-errors">What is a stack trace, and how can I use it to debug my application errors?</a> I have also checked this question but this explains how to look for error through stack trace. I already know that error is at line no 34 and it is null pointer exception. I want to know that how can an Insert statement throw null pointer exception even when all of the variables going in are not null.</p>
  
  <p>Thanks in Advance.</p>