title: Android : Setvisibility to visible causes nullpointerexception on button
body: <p>This seems to have been asked in stackoverflow a bit before with no convincing answers for most questions. anyways, i attempt again. 
  I have an Android App where am displaying a list where each row has an Edittext and Button component as seen below</p>
  
  <p><img src="https://i.stack.imgur.com/VLCOs.png" alt="enter image description here"></p>
  
  <p>The Edittext is non-editable when the view appears. I do this with the code below:</p>
  
  <pre><code>private void setNameAsEditable (View rowView, boolean setToEditable) {
  
      EditText textView = (EditText) rowView
              .findViewById(R.id.edittext_name);
      textView.setFocusableInTouchMode(setToEditable);
      textView.setFocusable(setToEditable);
  
      ImageButton button = (ImageButton) rowView
              .findViewById(R.id.button_save_name);
  
              if ( setToEditable ) {
  
                      button.setVisibility (View.VISIBLE);  // nullpointerexception here
      } else {
          button.setVisibility (View.GONE);
      }
  </code></pre>
  
  <p>When I long-press, and setToEditable is true, it throws nullpointerexception in the line indicated above. it doesn't seem to find the button component. However, 'button.setVisibility (View.GONE);' is executed when setToEditable is false without any issue.</p>
  
  <p>Can someone please help?</p>