title: Null pointer exception after click a button (SQLite database)
body: <p>I get a null pointer exception and my app closes when I click on the confirm button the save data to sqlite database. I really have no idea what is wrong here...</p>
  
  <pre><code>public class Morfologia extends Activity {
  
       DatabaseAdapter dbAdapter2;
  
  
      private EditText editTextHem;
  
      private Button button10;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_morfologia);
  
          editTextHem = (EditText) findViewById(R.id.editText1_hemoglobina);
          button10 = (Button) findViewById(R.id.button1_morfologia);
          button10.setOnClickListener(l2);
  
      }
  
      private OnClickListener l2 = new OnClickListener() {
  
          @Override
          public void onClick(View v) {
              if (v.getId() == R.id.button1_morfologia){
                  saveToDB();
              }
  
          }
      };
  
  
      public void saveToDB() {
  
          String hemoglobina = editTextHem.getText().toString();
          Log.d("text: ", hemoglobina);
  
          dbAdapter2.open();
          dbAdapter2.insertMorphologyData(hemoglobina);
          dbAdapter2.close();
      }}
  </code></pre>
  
  <p>LOGCAT:</p>
  
  <pre><code>11-04 10:49:37.734: D/text:(21197): 123
  11-04 10:49:37.734: D/AndroidRuntime(21197): Shutting down VM
  11-04 10:49:37.734: W/dalvikvm(21197): threadid=1: thread exiting with uncaught exception (group=0x416ced40)
  11-04 10:49:37.736: E/AndroidRuntime(21197): FATAL EXCEPTION: main
  11-04 10:49:37.736: E/AndroidRuntime(21197): Process: com.example.bmicalculator, PID: 21197
  11-04 10:49:37.736: E/AndroidRuntime(21197): java.lang.NullPointerException
  11-04 10:49:37.736: E/AndroidRuntime(21197):    at com.example.bmicalculator.Morfologia.saveToDB(Morfologia.java:54)
  11-04 10:49:37.736: E/AndroidRuntime(21197):    at com.example.bmicalculator.Morfologia$1.onClick(Morfologia.java:42)
  11-04 10:49:37.736: E/AndroidRuntime(21197):    at android.view.View.performClick(View.java:4456)
  11-04 10:49:37.736: E/AndroidRuntime(21197):    at android.view.View$PerformClick.run(View.java:18465)
  11-04 10:49:37.736: E/AndroidRuntime(21197):    at android.os.Handler.handleCallback(Handler.java:733)
  11-04 10:49:37.736: E/AndroidRuntime(21197):    at android.os.Handler.dispatchMessage(Handler.java:95)
  11-04 10:49:37.736: E/AndroidRuntime(21197):    at android.os.Looper.loop(Looper.java:136)
  11-04 10:49:37.736: E/AndroidRuntime(21197):    at android.app.ActivityThread.main(ActivityThread.java:5086)
  11-04 10:49:37.736: E/AndroidRuntime(21197):    at java.lang.reflect.Method.invokeNative(Native Method)
  11-04 10:49:37.736: E/AndroidRuntime(21197):    at java.lang.reflect.Method.invoke(Method.java:515)
  11-04 10:49:37.736: E/AndroidRuntime(21197):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
  11-04 10:49:37.736: E/AndroidRuntime(21197):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
  11-04 10:49:37.736: E/AndroidRuntime(21197):    at dalvik.system.NativeStart.main(Native Method)
  </code></pre>
  
  <p>Class with saveToDB method:</p>
  
  <pre><code>package com.example.bmicalculator.database;
  
  
  
  public class DatabaseAdapter {
  
      SQLiteDatabase database;
      DatabaseOpenHelper dbHelper;
  
      public DatabaseAdapter(Context context) {
          dbHelper = new DatabaseOpenHelper(context);
      }
  
      public void open() {
          database = dbHelper.getWritableDatabase();
      }
  
      public void close() {
          database.close();
      }
  
  
  
  
      public void insertMorphologyData(String hemoglobina){
          ContentValues values2 = new ContentValues();
          values2.put("hemoglobina", hemoglobina);
          database.insert("morfologia_krwi2", null, values2);
      }
  
  
  
  }
  </code></pre>
  
  <p>Class creating table:</p>
  
  <pre><code>public class DatabaseOpenHelper extends SQLiteOpenHelper {
  
      public static final String dbName = "baza";
  
  
      public static final String  morphologyTableName = "morfologia_krwi2";
  
      public static final String createTableMorphology = "CREATE TABLE " + morphologyTableName + 
              "(id INTEGER PRIMARY KEY AUTOINCREMENT," +
              "hemoglobina TEXT);";
  
  
      public DatabaseOpenHelper(Context context) {
          super(context, dbName, null, 1);
          // TODO Auto-generated constructor stub
      }
  
  
      @Override
      public void onCreate(SQLiteDatabase database) {
          // TODO Auto-generated method stub
          database.execSQL(createTableMorphology);
  
  
      }
  
  
      @Override
      public void onUpgrade(SQLiteDatabase database, int oldVersion, int newVersion) {
          // TODO Auto-generated method stub
  
      }
  
  
  
  }
  </code></pre>