title: Attempt to invoke virtual method 'void android.arch.lifecycle.LiveData.observe on a null object reference
body: <p>I am getting the following error</p>
  <p>I am using Android architecture components and tried to instantiate viewmodel and Observe data from LiveData. But im stuck here please help me solve this issue :</p>
  <pre><code>Attempt to invoke virtual method 'void android.arch.lifecycle.LiveData.observe(android.arch.lifecycle.LifecycleOwner, android.arch.lifecycle.Observer)' on a null object reference
  </code></pre>
  <p>My Fragment is this :
  While calling getCompany() method im getting and NullPoint Exception Error</p>
  <pre><code>    public class CompanyFragment extends LifecycleFragment {
      private CompanyViewModel companyViewModel;
  
      @Override
      public void onActivityCreated(@Nullable Bundle savedInstanceState) {
          super.onActivityCreated(savedInstanceState);
          companyViewModel = ViewModelProviders.of(this).get(CompanyViewModel.class);
          companyViewModel.initData();
          companyViewModel.getCompany().observe(this, new Observer&lt;CompanyEntity&gt;() {
              @Override
              public void onChanged(@Nullable CompanyEntity companyEntity) {
  
              }
          });
      }
      @Override
      public View onCreateView(LayoutInflater inflater,
                               @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
          return inflater.inflate(R.layout.fragment_company, container, false);
      }
  }
  </code></pre>
  <p>My ViewModel class is this :</p>
  <pre><code>public class CompanyViewModel extends ViewModel {
      private LiveData&lt;CompanyEntity&gt; companyEntityLiveData;
      private CompanyRepository companyRepo;
  
      public CompanyViewModel() {}
  
      public CompanyViewModel(CompanyRepository companyRepo){
          this.companyRepo = companyRepo;
      }
  
      public void initData(){
          companyEntityLiveData = companyRepo.getCompany();
      }
  
      public LiveData&lt;CompanyEntity&gt; getCompany() {
          return companyEntityLiveData;
      }
  
  }
  </code></pre>
  <p>Error is at this line :</p>
  <pre><code>   companyViewModel.getCompany().observe(this, new Observer&lt;CompanyEntity&gt;() {
          @Override
          public void onChanged(@Nullable CompanyEntity companyEntity) {
  
          }
      });
  </code></pre>
  <p>This is my CompanyRepository class:</p>
  <pre><code>public class CompanyRepository {
  private WebService webService;
  
      public CompanyRepository(){
  
      }
  
      public LiveData&lt;CompanyEntity&gt; getCompany() {
          final MutableLiveData&lt;CompanyEntity&gt; data = new MutableLiveData&lt;&gt;();
  
          webService.getCompany().enqueue(new Callback&lt;CompanyEntity&gt;() {
              @Override
              public void onResponse(Call&lt;CompanyEntity&gt; call, Response&lt;CompanyEntity&gt; response) {
                  data.setValue(response.body());
              }
  
              @Override
              public void onFailure(Call&lt;CompanyEntity&gt; call, Throwable t) {
  
              }
          });
  
          return data;
      }
  }
  </code></pre>