title: Android - custom ArrayAdapter
body: <p>Could anybody help me solve my problem.
  I still trying work with <code>DraggingListView</code> and <code>ArrayAdapter</code>.
  Now i want realize delete element from <code>listview</code> by click, but when i making :</p>
  
  <pre><code>StableArrayAdapter.this.notifyDataSetChanged();
  </code></pre>
  
  <p>i get <code>nullPointer Exception</code> ...</p>
  
  <p>here is my adapter:</p>
  
  <pre><code>public class StableArrayAdapter extends ArrayAdapter&lt;Product&gt; {
  
      final int INVALID_ID = -1;
      LayoutInflater lInflater;
      Context ctx;
      public static final String PREFS_NAME = "com.shvedchenko.skleroshop";
      public static final String PREFS_THEME = "theme";
  
      HashMap&lt;Product, Integer&gt; mIdMap = new HashMap&lt;Product, Integer&gt;();
  
      public StableArrayAdapter(Context context, int textViewResourceId, List&lt;Product&gt; prod) {
          super(context, textViewResourceId, /*objects*/prod);
          lInflater = (LayoutInflater) context
                  .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
          ctx = context;
          for (int i = 0; i &lt; prod.size(); ++i) {
              mIdMap.put(prod.get(i), i);
          }
      }
  
  
      // пункт списка
      @Override
      public View getView(final int position, View convertView, final ViewGroup parent) {
          // используем созданные, но не используемые view
          View view = convertView;
          if (view == null) {
              view = lInflater.inflate(R.layout.item, parent, false);
          }
  
          Product p = getItem(position);
  
          SharedPreferences pref = ctx.getSharedPreferences(PREFS_NAME, ctx.MODE_PRIVATE);
          int theme = pref.getInt(PREFS_THEME, 0);             // getting Integer
  
          if(theme == 0)
              ((TextView) view.findViewById(R.id.tvDescr)).setTextColor(Color.WHITE);
          else
              ((TextView) view.findViewById(R.id.tvDescr)).setTextColor(Color.BLACK);
  
          ((TextView) view.findViewById(R.id.tvDescr)).setText(p.getProductName());
          ((ImageView) view.findViewById(R.id.ivImage)).setImageResource(p.getProductImage());
  
          ImageView iv = (ImageView)view.findViewById(R.id.ivImage);
          iv.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View view) {
                  mIdMap.remove(getItem(position));
                  System.out.println("FROM CLICK -- " + mIdMap.size() );
                  /*for( Product p : mIdMap.keySet() ) {
                      System.out.println( p.getProductName() );
                  }*/
                  //StableArrayAdapter.this.notifyDataSetChanged();
              }
          });
  
          return view;
      }
  
      /*@Override
      public Object getItem(int position) {
          return mIdMap.get(position);
      }*/
  
  
      @Override
      public long getItemId(int position) {
          if (position &lt; 0 || position &gt;= mIdMap.size()) {
              return INVALID_ID;
          }
          Product item = (Product) getItem(position);
          return mIdMap.get(item);
      }
  
      @Override
      public boolean hasStableIds() {
          return true;
      }
  
  }
  </code></pre>
  
  <p>here is the error: </p>
  
  <blockquote>
    <p>08-26 08:50:58.902    2167-2167/com.shvedchenko.skleroshop
    E/AndroidRuntime﹕ FATAL EXCEPTION: main
    java.lang.NullPointerException
                at com.shvedchenko.skleroshop.StableArrayAdapter.getItemId(StableArrayAdapter.java:104)
                at android.widget.AdapterView.rememberSyncState(AdapterView.java:1195)
                at android.widget.AdapterView$AdapterDataSetObserver.onChanged(AdapterView.java:810)
                at android.widget.AbsListView$AdapterDataSetObserver.onChanged(AbsListView.java:5958)
                at android.database.DataSetObservable.notifyChanged(DataSetObservable.java:37)
                at android.widget.BaseAdapter.notifyDataSetChanged(BaseAdapter.java:50)
                at android.widget.ArrayAdapter.notifyDataSetChanged(ArrayAdapter.java:286)
                at com.shvedchenko.skleroshop.StableArrayAdapter$1.onClick(StableArrayAdapter.java:85)
                at android.view.View.performClick(View.java:4204)
                at android.view.View$PerformClick.run(View.java:17355)
                at android.os.Handler.handleCallback(Handler.java:725)
                at android.os.Handler.dispatchMessage(Handler.java:92)
                at android.os.Looper.loop(Looper.java:137)
                at android.app.ActivityThread.main(ActivityThread.java:5041)
                at java.lang.reflect.Method.invokeNative(Native Method)
                at java.lang.reflect.Method.invoke(Method.java:511)
                at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
                at dalvik.system.NativeStart.main(Native Method)</p>
  </blockquote>
  
  <p>/<em>UPDATED</em>/</p>
  
  <p>My adapter now:</p>
  
  <pre><code>public class StableArrayAdapter extends ArrayAdapter&lt;Product&gt; {
  
      final int INVALID_ID = -1;
      LayoutInflater lInflater;
      Context ctx;
      public static final String PREFS_NAME = "com.shvedchenko.skleroshop";
      public static final String PREFS_THEME = "theme";
  
      HashMap&lt;Product, Integer&gt; mIdMap = new HashMap&lt;Product, Integer&gt;();
      ArrayList&lt;Product&gt; prods = new ArrayList&lt;Product&gt;();
  
      public StableArrayAdapter(Context context, int textViewResourceId, List&lt;Product&gt; prod) {
          super(context, textViewResourceId, /*objects*/prod);
          lInflater = (LayoutInflater) context
                  .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
          ctx = context;
          for (int i = 0; i &lt; prod.size(); ++i) {
              mIdMap.put(prod.get(i), i);
              prods.add(i,prod.get(i));
          }
      }
  
  
      // пункт списка
      @Override
      public View getView(final int position, View convertView, final ViewGroup parent) {
          // используем созданные, но не используемые view
          View view = convertView;
          if (view == null) {
              view = lInflater.inflate(R.layout.item, parent, false);
          }
  
          Product p = getItem(position);
  
          SharedPreferences pref = ctx.getSharedPreferences(PREFS_NAME, ctx.MODE_PRIVATE);
          int theme = pref.getInt(PREFS_THEME, 0);             // getting Integer
  
          if(theme == 0)
              ((TextView) view.findViewById(R.id.tvDescr)).setTextColor(Color.WHITE);
          else
              ((TextView) view.findViewById(R.id.tvDescr)).setTextColor(Color.BLACK);
  
          ((TextView) view.findViewById(R.id.tvDescr)).setText(p.getProductName());
          ((ImageView) view.findViewById(R.id.ivImage)).setImageResource(p.getProductImage());
  
          ImageView iv = (ImageView)view.findViewById(R.id.ivImage);
          iv.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View view) {
                  prods.remove(position);
                  StableArrayAdapter.this.notifyData(prods);
  
              }
          });
  
          return view;
      }
  
      public void notifyData(List&lt;Product&gt; prod) {
  
          //First of all Clear Map
          mIdMap.clear();
          for (int i = 0; i &lt; prod.size(); ++i) {
              mIdMap.put(prod.get(i), i);
          }
  
          notifyDataSetChanged();
      }
  
  
      @Override
      public long getItemId(int position) {
          if (position &lt; 0 || position &gt;= mIdMap.size()) {
              return INVALID_ID;
          }
          Product item = (Product) getItem(position);
          return mIdMap.get(item);
      }
  
      @Override
      public boolean hasStableIds() {
          return true;
      }
  
  }
  </code></pre>
  
  <p>/<em>ERROR</em>/</p>
  
  <blockquote>
    <p>08-26 09:53:19.270    2530-2530/com.shvedchenko.skleroshop E/AndroidRuntime﹕ FATAL EXCEPTION: main
        java.lang.NullPointerException
                at com.shvedchenko.skleroshop.StableArrayAdapter.getItemId(StableArrayAdapter.java:122)
                at android.widget.AdapterView.rememberSyncState(AdapterView.java:1195)
                at android.widget.AdapterView$AdapterDataSetObserver.onChanged(AdapterView.java:810)
                at android.widget.AbsListView$AdapterDataSetObserver.onChanged(AbsListView.java:5958)
                at android.database.DataSetObservable.notifyChanged(DataSetObservable.java:37)
                at android.widget.BaseAdapter.notifyDataSetChanged(BaseAdapter.java:50)
                at android.widget.ArrayAdapter.notifyDataSetChanged(ArrayAdapter.java:286)
                at com.shvedchenko.skleroshop.StableArrayAdapter.notifyData(StableArrayAdapter.java:112)
                at com.shvedchenko.skleroshop.StableArrayAdapter$1.onClick(StableArrayAdapter.java:91)</p>
  </blockquote>
  
  <p>What i am doing wrong?</p>
  
  <p>TNX in advance!</p>