title: Edittext.gettext return null without
body: <p>In my app, I have to type task id (which is generated in a different activity) and press the get_data button to fetch data. I have recently added code to automatically .settext in Task id Edittext after getting string from Sharedprefrence. Whenever this activity is created Task id Edittext is showing task string caught from Sharedprefrence perfectly but whenever I click get_data button app crash on Null pointer exception but <strong>if I just click on Task Id Edittext without changing anything just tap on Edittext the keyboard popup and I press get_data button everything works fine.</strong> I even had a condition to check if Edittext is Empty or not</p>
  <pre><code> public View onCreateView(LayoutInflater inflater, ViewGroup container,
                               Bundle savedInstanceState) {
          // Inflate the layout for this fragmen;
          View view = inflater.inflate(R.layout.fragment_d_c_u__reading_by_task, container, false);
          find_view_by_id(view);
          set_on_click_litioner();
          pref = getActivity().getSharedPreferences(&quot;my_pref&quot;, MODE_PRIVATE);
          Taskid = pref.getString(&quot;Task_ID&quot;,&quot;&quot;);
          taskid_edt.setText(Taskid);
        .....
  }
  </code></pre>
  <pre><code>public void onClick(View v) {
          switch (v.getId()) {
              
              case R.id.get_data_btn:
                 
                  if (taskid_edt.getText().toString().isEmpty()) {
                      Toast.makeText(getContext(), &quot;Please Enter Task ID&quot;, Toast.LENGTH_SHORT).show();
                  } else {
                      AsyncTask1 asyntask = new AsyncTask1();
                      asyntask.execute();
                  }
                  break;
  }
  }
  </code></pre>
  <p>ERROR</p>
  <pre><code>AndroidRuntime: FATAL EXCEPTION: main
      Process: amr_handheld.com.handheld, PID: 31544
      java.lang.NullPointerException: Attempt to invoke virtual method 'android.os.IBinder android.view.View.getWindowToken()' on a null object reference
          at amr_handheld.Fragment.DCU_Reading_byTask.onClick(DCU_Reading_byTask.java:178)
          at android.view.View.performClick(View.java:7158)
          at android.view.View.performClickInternal(View.java:7135)
          at android.view.View.access$3500(View.java:801)
          at android.view.View$PerformClick.run(View.java:27373)
          at android.os.Handler.handleCallback(Handler.java:883)
          at android.os.Handler.dispatchMessage(Handler.java:100)
          at android.os.Looper.loop(Looper.java:239)
          at android.app.ActivityThread.main(ActivityThread.java:7441)
          at java.lang.reflect.Method.invoke(Native Method)
          at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:935)
  </code></pre>