title: I want to fetch all the values of EditText from fragments inside a viewpager and want to use them in activity?
body: <p>Below is my fragment class from which I want to fetch values, but it is giving me error.</p>
  
  <pre><code> @Nullable
          @Override
          public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
              rootView = inflater.inflate(R.layout.fragment_register_company, container, false);
  
              bindViews();
  
  
              return rootView;
          }
  
          private void bindViews() {
              companyName = rootView.findViewById(R.id.companyName);
              compAddress1 = rootView.findViewById(R.id.compAddress1);
              compAddress2 = rootView.findViewById(R.id.compAddress2);
              compCountry = rootView.findViewById(R.id.compCountry);
              compState = rootView.findViewById(R.id.compState);
              compCity = rootView.findViewById(R.id.compCity);
              compWebsite = rootView.findViewById(R.id.compWebsite);
              compEmail = rootView.findViewById(R.id.compEmail);
              compPhone = rootView.findViewById(R.id.compPhone);
  
          }
  
          public HashMap&lt;String, String&gt; getCompanyDetails() {
  
              companyNameString = companyName.getText().toString();
              compAddress1String = compAddress1.getText().toString();
              compAddress2String = compAddress2.getText().toString();
              compCountryString = compCountry.getText().toString();
              compStateString = compState.getText().toString();
              compCityString = compCity.getText().toString();
              compWebsiteString = compWebsite.getText().toString();
              compEmailString = compEmail.getText().toString();
              compPhoneString = compPhone.getText().toString();
  
  
              HashMap&lt;String, String&gt; map = new HashMap&lt;&gt;();
              map.put("companyNameString", companyNameString);
              map.put("compAddress1String", compAddress1String);
              map.put("compAddress2String", compAddress2String);
              map.put("compCountryString", compCountryString);
              map.put("compStateString", compStateString);
              map.put("compCityString", compCityString);
              map.put("compWebsiteString", compWebsiteString);
              map.put("compEmailString", compEmailString);
              map.put("compPhoneString", compPhoneString);
  
              return map;
  
          }
  </code></pre>
  
  <p>This is my function inside my Main Activity from which I am trying to fetch values.</p>
  
  <pre><code> private void collectData() {
  
  
          HashMap&lt;String, String&gt; compMap= new RegisterCompanyFragment().getCompanyDetails();
  
  
  
          companyNameString = compMap.get("companyNameString");
          compAddress1String = compMap.get("compAddress1String");
          compAddress2String = compMap.get("compAddress2String");
          compCountryString = compMap.get("compCountryString");
          compStateString = compMap.get("compStateString");
          compCityString = compMap.get("compCityString");
          compWebsiteString = compMap.get("compWebsiteString");
          compEmailString = compMap.get("compEmailString");
          compPhoneString = compMap.get("compPhoneString");
  
  
  
  
      }
  </code></pre>
  
  <p>Here is the error, I guess this error is because the edit-text has not bind to the view and still I am trying to use it. So kindly help me to resolve this by providing a method to access the values of edit text from the fragment. For more information kindly comment below. Thank You.</p>
  
  <pre><code>E/AndroidRuntime: FATAL EXCEPTION: main
                    Process: com.jagmad.jhea, PID: 30128
                    java.lang.NullPointerException: Attempt to invoke virtual method 'android.text.Editable android.widget.EditText.getText()' on a null object reference
                        at com.jagmad.jhea.Registration.RegisterCompanyFragment.getCompanyDetails(RegisterCompanyFragment.java:75)
                        at com.jagmad.jhea.Registration.CompanyRegistration.collectData(CompanyRegistration.java:186)
                        at com.jagmad.jhea.Registration.CompanyRegistration.onOptionsItemSelected(CompanyRegistration.java:139)
                        at android.app.Activity.onMenuItemSelected(Activity.java:3208)
                        at android.support.v4.app.FragmentActivity.onMenuItemSelected(FragmentActivity.java:407)
                        at android.support.v7.app.AppCompatActivity.onMenuItemSelected(AppCompatActivity.java:195)
                        at android.support.v7.view.WindowCallbackWrapper.onMenuItemSelected(WindowCallbackWrapper.java:108)
                        at android.support.v7.app.AppCompatDelegateImplV9.onMenuItemSelected(AppCompatDelegateImplV9.java:674)
                        at android.support.v7.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:822)
                        at android.support.v7.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:171)
                        at android.support.v7.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:973)
                        at android.support.v7.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:963)
                        at android.support.v7.widget.ActionMenuView.invokeItem(ActionMenuView.java:624)
                        at android.support.v7.view.menu.ActionMenuItemView.onClick(ActionMenuItemView.java:150)
                        at android.view.View.performClick(View.java:5612)
                        at android.view.View$PerformClick.run(View.java:22288)
                        at android.os.Handler.handleCallback(Handler.java:751)
                        at android.os.Handler.dispatchMessage(Handler.java:95)
                        at android.os.Looper.loop(Looper.java:154)
                        at android.app.ActivityThread.main(ActivityThread.java:6123)
                        at java.lang.reflect.Method.invoke(Native Method)
                        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
                        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:757)
  </code></pre>