title: How to display id from SQLite db click on listView item in Android?
body: <p>I want to retrieve id from <code>SQLiteDatabase</code> when click on <code>ListView</code> item in next activity. When I run the application it getting <code>NullPointerException</code>.</p>
  
  <p>I have declare id in String in <code>DataBase_Adapter class</code>:</p>
  
  <pre><code>public static final String KEY_NEW_LEAD_ID ="id";
  </code></pre>
  
  <p>Here is my ListView Code:</p>
  
  <pre><code>displayDataList = (ListView)findViewById(R.id.listViewGetAllData);
  
  displayDataList.setOnItemClickListener(new OnItemClickListener() {
  
      @Override
      public void onItemClick(AdapterView&lt;?&gt; arg0, View arg1, int position,
              long arg3) {
          // TODO Auto-generated method stub
  
          Intent ii=new Intent(Display_All_Data.this ,New_Lead_Detail_Activity.class);
          cursor = (Cursor) displayDataAdapter.getItem(position);
          int i=cursor.getInt(cursor.getColumnIndex("id"));
          System.out.println("ID = " + i);
          ii.putExtra("NEW_LEAD_USER_ID", i);
          startActivity(ii);
      }
  });
  </code></pre>
  
  <p>Here is my Log Cat Info:</p>
  
  <pre><code>12-17 17:50:26.024: E/AndroidRuntime(10322): FATAL EXCEPTION: main
  12-17 17:50:26.024: E/AndroidRuntime(10322): java.lang.NullPointerException
  12-17 17:50:26.024: E/AndroidRuntime(10322):    at com.lead_management_project.Display_All_Data$1.onItemClick(Display_All_Data.java:48)
  12-17 17:50:26.024: E/AndroidRuntime(10322):    at android.widget.AdapterView.performItemClick(AdapterView.java:284)
  12-17 17:50:26.024: E/AndroidRuntime(10322):    at android.widget.ListView.performItemClick(ListView.java:3513)
  12-17 17:50:26.024: E/AndroidRuntime(10322):    at android.widget.AbsListView$PerformClick.run(AbsListView.java:1812)
  12-17 17:50:26.024: E/AndroidRuntime(10322):    at android.os.Handler.handleCallback(Handler.java:587)
  12-17 17:50:26.024: E/AndroidRuntime(10322):    at android.os.Handler.dispatchMessage(Handler.java:92)
  12-17 17:50:26.024: E/AndroidRuntime(10322):    at android.os.Looper.loop(Looper.java:123)
  12-17 17:50:26.024: E/AndroidRuntime(10322):    at android.app.ActivityThread.main(ActivityThread.java:3683)
  12-17 17:50:26.024: E/AndroidRuntime(10322):    at java.lang.reflect.Method.invokeNative(Native Method)
  12-17 17:50:26.024: E/AndroidRuntime(10322):    at java.lang.reflect.Method.invoke(Method.java:507)
  12-17 17:50:26.024: E/AndroidRuntime(10322):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
  12-17 17:50:26.024: E/AndroidRuntime(10322):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
  12-17 17:50:26.024: E/AndroidRuntime(10322):    at dalvik.system.NativeStart.main(Native Method)
  </code></pre>
  
  <p>This my Display_Data_Adapter class extends BaseAdapter</p>
  
  <pre><code>public class Display_Data_Adapter extends BaseAdapter
  {
      Context mContext;
      ArrayList&lt;String&gt; newLead_ArrayList_OrgName;
      ArrayList&lt;String&gt; newLead_ArrayList_Name;
      ArrayList&lt;String&gt; newLead_ArrayList_Status;
      ArrayList&lt;String&gt; newLead_ArrayList_Budget;
  
      /**
       * @param mContext
       * @param newLead_ArrayList_OrgName
       * @param newLead_ArrayList_Name
       * @param newLead_ArrayList_Status
       * @param newLead_ArrayList_Budget
       */
      protected Display_Data_Adapter(Context mContext,
              ArrayList&lt;String&gt; newLead_ArrayList_OrgName,
              ArrayList&lt;String&gt; newLead_ArrayList_Name,
              ArrayList&lt;String&gt; newLead_ArrayList_Status,
              ArrayList&lt;String&gt; newLead_ArrayList_Budget) {
          this.mContext = mContext;
          this.newLead_ArrayList_OrgName = newLead_ArrayList_OrgName;
          this.newLead_ArrayList_Name = newLead_ArrayList_Name;
          this.newLead_ArrayList_Status = newLead_ArrayList_Status;
          this.newLead_ArrayList_Budget = newLead_ArrayList_Budget;
      }
  
  
  
      /**
       * 
       */
      protected Display_Data_Adapter() {
          super();
          // TODO Auto-generated constructor stub
      }
  
  
      @Override
      public int getCount() {
          // TODO Auto-generated method stub
          return newLead_ArrayList_OrgName.size();
      }
  
      @Override
      public Object getItem(int position) {
          // TODO Auto-generated method stub
          return position;
      }
  
      @Override
      public long getItemId(int position) {
          // TODO Auto-generated method stub
          return position;
      }
  
      @Override
      public View getView(int position, View v, ViewGroup vg) 
      {
          // TODO Auto-generated method stub
  
          Holder mHolder;
          LayoutInflater layoutInflater;
  
          if (v == null)
          {
              layoutInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
              v = layoutInflater.inflate(R.layout.search_data_item_listview,null);
  
              mHolder = new Holder();
  
              mHolder.txt_newLead_OrgName = (TextView) v
                      .findViewById(R.id.textvieworgname);
  
              mHolder.txt_newLead_Name = (TextView) v
                      .findViewById(R.id.textviewname);
  
              mHolder.txt_newLead_Status = (TextView) v
                      .findViewById(R.id.textviewstatus);
  
  
              mHolder.txt_newLead_Budget = (TextView) v
                      .findViewById(R.id.textviewbudget);
  
              v.setTag(mHolder);
  
          } else {
  
              mHolder = (Holder) v.getTag();
  
          }
  
  
  
          mHolder.txt_newLead_OrgName.setText(newLead_ArrayList_OrgName.get(position));
  
          mHolder.txt_newLead_Name.setText(newLead_ArrayList_Name.get(position));
  
          mHolder.txt_newLead_Status.setText(newLead_ArrayList_Status.get(position));
  
          mHolder.txt_newLead_Budget.setText(newLead_ArrayList_Budget.get(position));
  
          return v;
  
  
      }
  
      public class Holder {
  
          TextView txt_newLead_OrgName;
          TextView txt_newLead_Name;
          TextView txt_newLead_Status;
          TextView txt_newLead_Budget;
  
      }
  
  }
  </code></pre>