title: Contact CRUD Function using SQLiteDataBase
body: <p>I am new to android development, i tried contact crud function which throwing NullPointer Exception error in onItemClick, Please help me..
      here is the code i tried,
  Workflow,
  1. Add New contact will save data in DB and list only FirstName in main Activity
  2. Select FirstName in list should goto Edit Activity and must fill resp. editText from DB</p>
  
  <pre><code>    enter code here
  **Main Activity**
  public class ContactActivity extends ListActivity {
      Intent objIntent;
      TextView contactId;
      DBContoller controller = new DBContoller(this);
  
       public void showAddForm(View view) {
              Intent showIntent = new Intent(getApplicationContext(), AddContact.class);
              startActivity(showIntent);
              }
      // public void closeShowAddForm(View view) {
          // Intent closeIntent = new Intent(getApplicationContext(), )
       //}
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.main);
  
          ArrayList&lt;HashMap&lt;String, String&gt;&gt; contactList =  controller.getAllContact();
          if(contactList.size()!=0) {
              ListView lv = getListView();
  
              lv.setOnItemClickListener(new OnItemClickListener() {
  
              //@Override
              public void onItemClick(AdapterView&lt;?&gt; parent, View view,int position, long id) {
                  contactId = (TextView) view.findViewById(R.id.CId);
                  String valContactId =contactId.getText().toString();
  
                  Intent  objIndent = new Intent(ContactActivity.this,EditContact.class);
  
                  objIndent.putExtra("str_CId", valContactId); 
                  startActivity(objIndent);
                  }
              });
                  ListAdapter adapter = new SimpleAdapter( ContactActivity.this, contactList, R.layout.view, new String[] {"CId","FirstName"}, new int[] {R.id.CId, R.id.FirstName,}); 
                  super.setListAdapter(adapter);
          }
          }
      }
  
  **Add Contact Activity**
  
  public class AddContact extends Activity{
  Button btnadd;
        EditText fname, lname, mail, phn,addr, web, blog;
        DBContoller controller = new DBContoller(this);
  
        @Override
        public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.add);
  
          fname = (EditText) findViewById(R.id.editText1);
          lname = (EditText) findViewById(R.id.editText2);
          mail  = (EditText) findViewById(R.id.editText3);
          phn   = (EditText) findViewById(R.id.editText4);
          addr  = (EditText) findViewById(R.id.editText5);
          web   = (EditText) findViewById(R.id.editText6);
          blog  = (EditText) findViewById(R.id.editText7);
  
          btnadd = (Button) findViewById(R.id.btnadd);
          btnadd.setOnClickListener(new OnClickListener() {
              public void onClick(View arg0) {
                  // TODO Auto-generated method stub
                  Intent objIntent = new Intent(getApplicationContext(), ContactActivity.class);
                  startActivity(objIntent);
  
                  String savefn = fname.getText().toString();
                  String saveln = lname.getText().toString();
                  String savemail = mail.getText().toString();
                  String savemob = phn.getText().toString();
                  String saveaddr = addr.getText().toString();
                  String saveweb = web.getText().toString();
                  String saveblog = blog.getText().toString();
  
                  HashMap&lt;String, String&gt; queryValues =  new  HashMap&lt;String, String&gt;();
                  queryValues.put("FirstName", fname.getText().toString());
                  queryValues.put("LastName", lname.getText().toString());
                  queryValues.put("Email", mail.getText().toString());
                  queryValues.put("Phone", phn.getText().toString());
                  queryValues.put("Address", addr.getText().toString());
                  queryValues.put("Website", web.getText().toString());
                  queryValues.put("Blog", blog.getText().toString());
  
  if(savefn.equals("")||savemail.equals("")||savemob.equals("")||saveaddr.equals("")&amp;&amp;saveln.equals("")&amp;&amp;saveweb.equals("")&amp;&amp;saveblog.equals("")) {
  Toast.makeText(getApplicationContext(), "Fields vacant",1500).show();
  return;
      } else {
      //dba.insertEntry(savefn, saveln, savemail, savemob, saveaddr, saveweb, saveblog);
      controller.insertContact(queryValues);
      Toast.makeText(getApplicationContext(), "Contact Saved Successfully" , 2000).show();
      //dba.close();
      return;
      } // this.callHomeActivity(view);
      }
      });
      }
  
  
        public void addNewContact(View view) {
  
        }
        //public void callHomeActivity(View view) {
         // Intent objIntent = new Intent(getApplicationContext(), ContactActivity.class);
         // startActivity(objIntent);
        } 
  
  
  **Edit Contact**
  
  public class AddContact extends Activity{
  Button btnadd;
        EditText fname, lname, mail, phn,addr, web, blog;
        DBContoller controller = new DBContoller(this);
  
        @Override
        public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.add);
  
          fname = (EditText) findViewById(R.id.editText1);
          lname = (EditText) findViewById(R.id.editText2);
          mail  = (EditText) findViewById(R.id.editText3);
          phn   = (EditText) findViewById(R.id.editText4);
          addr  = (EditText) findViewById(R.id.editText5);
          web   = (EditText) findViewById(R.id.editText6);
          blog  = (EditText) findViewById(R.id.editText7);
  
          btnadd = (Button) findViewById(R.id.btnadd);
          btnadd.setOnClickListener(new OnClickListener() {
              public void onClick(View arg0) {
                  // TODO Auto-generated method stub
                  Intent objIntent = new Intent(getApplicationContext(), ContactActivity.class);
                  startActivity(objIntent);
  
                  String savefn = fname.getText().toString();
                  String saveln = lname.getText().toString();
                  String savemail = mail.getText().toString();
                  String savemob = phn.getText().toString();
                  String saveaddr = addr.getText().toString();
                  String saveweb = web.getText().toString();
                  String saveblog = blog.getText().toString();
  
                  HashMap&lt;String, String&gt; queryValues =  new  HashMap&lt;String, String&gt;();
                  queryValues.put("FirstName", fname.getText().toString());
                  queryValues.put("LastName", lname.getText().toString());
                  queryValues.put("Email", mail.getText().toString());
                  queryValues.put("Phone", phn.getText().toString());
                  queryValues.put("Address", addr.getText().toString());
                  queryValues.put("Website", web.getText().toString());
                  queryValues.put("Blog", blog.getText().toString());
  
  if(savefn.equals("")||savemail.equals("")||savemob.equals("")||saveaddr.equals("")&amp;&amp;saveln.equals("")&amp;&amp;saveweb.equals("")&amp;&amp;saveblog.equals("")) {
  Toast.makeText(getApplicationContext(), "Fields vacant",1500).show();
  return;
      } else {
      //dba.insertEntry(savefn, saveln, savemail, savemob, saveaddr, saveweb, saveblog);
      controller.insertContact(queryValues);
      Toast.makeText(getApplicationContext(), "Contact Saved Successfully" , 2000).show();
      //dba.close();
      return;
      } // this.callHomeActivity(view);
      }
      });
      }
  
  
        public void addNewContact(View view) {
  
        }
        //public void callHomeActivity(View view) {
         // Intent objIntent = new Intent(getApplicationContext(), ContactActivity.class);
         // startActivity(objIntent);
        } 
  
  
  **DBController**
  public class DBContoller extends SQLiteOpenHelper{
      private static final String LOGCAT = null;
  
        public DBContoller(Context applicationcontext) {
          super(applicationcontext, "androidsqlite.db", null, 1);
          Log.d(LOGCAT,"Created");
        }
  
        @Override
        public void onCreate(SQLiteDatabase database) {
          String query;
          query = "CREATE TABLE CONTACT ( CId INTEGER PRIMARY KEY AUTOINCREMENT, FirstName TEXT, LastName TEXT, EMail TEXT, Mobile TEXT, Address TEXT, Website TEXT, Blog TEXT)";
          database.execSQL(query);
          Log.d(LOGCAT,"Contacts Created");
        }
        @Override
        public void onUpgrade(SQLiteDatabase database, int version_old, int current_version) {
          String query;
          query = "DROP TABLE IF EXISTS CONTACT";
          database.execSQL(query);
          onCreate(database);
        }
  
        public void insertContact(HashMap&lt;String, String&gt; queryValues) {
          SQLiteDatabase database = this.getWritableDatabase();
          ContentValues values = new ContentValues();
          values.put("Ins_FirstName", queryValues.get("FirstName"));
          values.put("Ins_LastName", queryValues.get("LastName"));
          values.put("Ins_Email", queryValues.get("Email"));
          values.put("Ins_Mobile", queryValues.get("Mobile"));
          values.put("Ins_Address", queryValues.get("Address"));
          values.put("Ins_Website", queryValues.get("Website"));
          values.put("Ins_Blog", queryValues.get("Blog"));
  
          database.insert("CONTACT", null, values);
          database.close();
        }
  
        public int updateContact(HashMap&lt;String, String&gt; queryValues) {
          SQLiteDatabase database = this.getWritableDatabase();  
          ContentValues values = new ContentValues();
          values.put("Upd_FirstName", queryValues.get("FirstName"));
          values.put("Upd_LastName", queryValues.get("LastName"));
          values.put("Upd_Email", queryValues.get("Email"));
          values.put("Upd_Mobile", queryValues.get("Mobile"));
          values.put("Upd_Address", queryValues.get("Address"));
          values.put("Upd_Website", queryValues.get("Website"));
          values.put("Upd_Blog", queryValues.get("Blog"));
  
          return database.update("CONTACT", values, "CId" + " = ?", new String[] { queryValues.get("CId") });
        }
  
        public void deleteContact(String id) {
          Log.d(LOGCAT,"delete");
          SQLiteDatabase database = this.getWritableDatabase();  
          String deleteQuery = "DELETE FROM  CONTACT where CId='"+ id +"'";
          Log.d("query",deleteQuery);   
          database.execSQL(deleteQuery);
        }
  
        public ArrayList&lt;HashMap&lt;String, String&gt;&gt; getAllContact() {
          ArrayList&lt;HashMap&lt;String, String&gt;&gt; wordList;
          wordList = new ArrayList&lt;HashMap&lt;String, String&gt;&gt;();
          String selectQuery = "SELECT  * FROM CONTACT";
          SQLiteDatabase database = this.getWritableDatabase();
          Cursor cursor = database.rawQuery(selectQuery, null);
          if (cursor.moveToFirst()) {
            do {
              HashMap&lt;String, String&gt; map = new HashMap&lt;String, String&gt;();
              map.put("CId", cursor.getString(0));
              map.put("FirstName", cursor.getString(1));
              wordList.add(map);
            } while (cursor.moveToNext());
          }
          return wordList;
        }
  
        public HashMap&lt;String, String&gt; getContactInfo(String id) {
          HashMap&lt;String, String&gt; wordList = new HashMap&lt;String, String&gt;();
          SQLiteDatabase database = this.getReadableDatabase();
          String selectQuery = "SELECT * FROM CONTACT where CId='"+id+"'";
          Cursor cursor = database.rawQuery(selectQuery,null);
          if (cursor.moveToFirst()) {
            do {
              wordList.put("FirstName", cursor.getString(1));
              wordList.put("LastName", cursor.getString(2));
              wordList.put("Email", cursor.getString(3));
              wordList.put("Mobile", cursor.getString(4));
              wordList.put("Address", cursor.getString(5));
              wordList.put("Website", cursor.getString(6));
              wordList.put("Blog", cursor.getString(7));
            } while (cursor.moveToNext());
          }           
          return wordList;
        } 
  }
  </code></pre>
  
  <p>Logcat errors;
  01-17 20:32:34.651: D/(286): Created
  01-17 20:33:13.581: D/AndroidRuntime(286): Shutting down VM
  01-17 20:33:13.581: W/dalvikvm(286): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
  01-17 20:33:13.621: E/AndroidRuntime(286): FATAL EXCEPTION: main
  01-17 20:33:13.621: E/AndroidRuntime(286): java.lang.NullPointerException
  01-17 20:33:13.621: E/AndroidRuntime(286):  at com.example.contact.ContactActivity$1.onItemClick(ContactActivity.java:41)
  01-17 20:33:13.621: E/AndroidRuntime(286):  at android.widget.AdapterView.performItemClick(AdapterView.java:284)
  01-17 20:33:13.621: E/AndroidRuntime(286):  at android.widget.ListView.performItemClick(ListView.java:3382)
  01-17 20:33:13.621: E/AndroidRuntime(286):  at android.widget.AbsListView$PerformClick.run(AbsListView.java:1696)
  01-17 20:33:13.621: E/AndroidRuntime(286):  at android.os.Handler.handleCallback(Handler.java:587)
  01-17 20:33:13.621: E/AndroidRuntime(286):  at android.os.Handler.dispatchMessage(Handler.java:92)
  01-17 20:33:13.621: E/AndroidRuntime(286):  at android.os.Looper.loop(Looper.java:123)
  01-17 20:33:13.621: E/AndroidRuntime(286):  at android.app.ActivityThread.main(ActivityThread.java:4627)
  01-17 20:33:13.621: E/AndroidRuntime(286):  at java.lang.reflect.Method.invokeNative(Native Method)
  01-17 20:33:13.621: E/AndroidRuntime(286):  at java.lang.reflect.Method.invoke(Method.java:521)
  01-17 20:33:13.621: E/AndroidRuntime(286):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
  01-17 20:33:13.621: E/AndroidRuntime(286):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
  01-17 20:33:13.621: E/AndroidRuntime(286):  at dalvik.system.NativeStart.main(Native Method)
  01-17 20:33:17.341: I/Process(286): Sending signal. PID: 286 SIG: 9</p>