title: Android: Fragment inside Activity. NullPointerException when getting View from Fragment
body: <p>Users have a crash. I know why but I do not know how to fix it. I am newbie in android dev.</p>
  
  <p>Situation:
  Android: Fragment inside Activity. Fragment has an EditText. Activity has a button. User tap the button. Inside Button.OnClick() I want to get text  Fragment.EditText.getText();
  Some users have a crash here EditText.getText(). i.e. EditText is null.</p>
  
  <p>How I do:</p>
  
  <pre><code>In Activity:
  public class MyAcrivity extends AppCompatActivity implements OnFragmentInteractionListener {
  
      final MyFrag myFrag= MyFrag.newInstance();
  
      public void run(final View view) {
           //some users have crash here because getEt() return null
          final String str = myFrag.getEt().getText().toString(); 
      }
  
  }
  </code></pre>
  
  <p>In Fragment:</p>
  
  <pre><code>public class MyFrag extends Fragment {
  
      private EditText et;
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
          // Inflate the layout for this fragment
          View view = inflater.inflate(R.layout.fragment_myfrag, container, false);
          et = (EditText) view.findViewById(R.id.et);
          return view;
      }
  
      @Override
      public void onViewCreated(View view, Bundle savedInstanceState) {
          super.onViewCreated(view, savedInstanceState);
  
          et = (EditText) view.findViewById(R.id.et);
      }
  
      public EditText getEt() {
          // return (EditText) getView().findViewById(R.id.et); here getView() could be nul too
          return et;
      }
  
  
  }
  </code></pre>
  
  <ul>
  <li>I know getView() could be null (already googled it).</li>
  <li>Init "View" inside onCreateView useless. Crash still happend.</li>
  <li>Init "View" inside onViewCreated useless. Crash still happend.</li>
  </ul>
  
  <p>I can NOT reproduce this crash in emulator or my smartphone. I have stable work of my app. BUT some users have the crash and Fabric(crashlytics) is sending messages about it.</p>
  
  <p>People! Help! How to obtain some View from Fragment correctly? I can not to find answers from lifecycle of Fragment. Please explain to me what is wrong.</p>