title: Removing Dynamically added views in android crashing application on view ClickListener for removing
body: <p>I want to implement the dynamically add and removing Views in android layout and Save the changes in shared preferences,<br/><br/> Everything works fine But while i m clicking on the specific view to remove on that specific view ClickListener something went wrong and its crashing the application but its removing that view and displaying the remaining rows after i restart application</p>
  
  <p>here are my codes<br/>
  Any Help would be much appriciated<br/></p>
  
  <pre><code>public void display_contacts()
  {
      View.OnClickListener removeListener=new View.OnClickListener()
      {
          public void onClick(View paramAnonymousView)
          {
              TextView removeNum=(TextView)paramAnonymousView.findViewById(R.id.contact_name1);
              if(paramAnonymousView.getId() == R.id.viewId)
              {
                  mSettings.Initialize(getApplicationContext());
                  mSettings.RemoveFromContactList(removeNum.getText().toString());
                  mSettings.SaveSettings();
                  LinearLayout displayView = (LinearLayout)mActivity.findViewById(R.id.contacts_view);
                  displayView.removeView(paramAnonymousView);
                  displayView.invalidate();
              }
          }
      };
  
      LinearLayout wrapper = (LinearLayout) findViewById(R.id.contacts_view);
      LinearLayout inflatedView;
      mSettings.Initialize(getApplicationContext());
      int i=mSettings.GetContactListCount();
      if(i&gt;0) {
      final   String[] arrayOfStrings2 = mSettings.GetContactListNumber();
      final    String[] arrayOfStrings3 = mSettings.GetContactListName();
          for (int j = 0; j &lt; i; j++) {
              String str = arrayOfStrings2[j];
              if (arrayOfStrings3[j] != null) {
                  str = arrayOfStrings3[j] + "(" + arrayOfStrings2[j] + ")";
              }
              inflatedView = (LinearLayout) View.inflate(this, R.layout.allow_deny_row, null);
              ((TextView) inflatedView.findViewById(R.id.contact_name1)).setText(str);
              inflatedView.setId(R.id.viewId);
              wrapper.addView(inflatedView);
              wrapper.invalidate();
              inflatedView.setOnClickListener(removeListener);
          }
  
      }
  
  }
  </code></pre>
  
  <p>something went wrong on view and onClickListener<br/><br/>
  thanks in advance </p>
  
  <p><strong>Update: error log</strong></p>
  
  <pre><code>01-03 15:46:33.112 17483-17483/com.example.ghaznavi.contacts D/HAWAII_EGL: Set SWAP INTERVAL 0
  01-03 15:46:33.112 17483-17483/com.example.ghaznavi.contacts D/HAWAII_EGL: eglCreateWindowSurface() surface: 0x4fc82108, VC surface: 1, Thread: 17483
  01-03 15:46:33.112 17483-17483/com.example.ghaznavi.contacts D/HAWAII_EGL: eglMakeCurrent(0x4fc5e2c8, 0x4fc82108, 0x4fc82108) Thread: 17483
  01-03 15:46:33.122 17483-17483/com.example.ghaznavi.contacts D/OpenGLRenderer: Enabling debug mode 0
  01-03 15:46:52.021 17483-17483/com.example.ghaznavi.contacts D/AndroidRuntime: Shutting down VM
  01-03 15:46:52.021 17483-17483/com.example.ghaznavi.contacts W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0x41b05960)
  01-03 15:46:52.031 17483-17483/com.example.ghaznavi.contacts E/AndroidRuntime: FATAL EXCEPTION: main
                                                                                 java.lang.NullPointerException
                                                                                     at com.example.ghaznavi.contacts.Contact_main$4.onClick(Contact_main.java:132)
                                                                                     at android.view.View.performClick(View.java:4380)
                                                                                     at android.view.View$PerformClick.run(View.java:18094)
                                                                                     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:5279)
                                                                                     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:1102)
                                                                                     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
                                                                                     at dalvik.system.NativeStart.main(Native Method)
  01-03 15:47:10.379 17483-17483/com.example.ghaznavi.contacts I/Process: Sending signal. PID: 17483 SIG: 9
  </code></pre>