title: Room + Live Data Debugging
body: <p>I am trying to make a login function which will check if the username exists in db:-</p>
  
  <p>I need to get the live data successfully from Room database to Repository to view-model. Below is the code. It isnt working but will try one of the suggestion already. </p>
  
  <p>when i load from DB line :-</p>
  
  <pre><code> UserDetails= dao.loadUserDetails(UserName);
      Log.v("Response", UserDetails.getValue().getToken());
  </code></pre>
  
  <p>I get cannot invoke Null.....      </p>
  
  <p>I am confused about whats the best way also to implement such a function and how to fix this.</p>
  
  <p>Repository</p>
  
  <pre><code>public MutableLiveData&lt;String&gt; LoginUser(String UserName,String Password ) {
  //
  //        rUserDetails.setUsername("nadeem");
  //        rUserDetails.setPassword("test");
  //        rUserDetails.setToken(AppConstants.PARAMS);
  //        rUserDetails.setSid("1234");
  //        rUserDetails.setResourcId(Long.valueOf(12134));
  //        insert(rUserDetails);
  
  
       UserDetails= dao.loadUserDetails(UserName);
      Log.v("Response", UserDetails.getValue().getToken());
  
      if(UserDetails.getValue()!=null) {
          rUserDetails.setUsername(UserName);
          rUserDetails.setPassword(Password);
          rUserDetails.setToken(AppConstants.PARAMS);
          Observable&lt;MainResponse&gt; mainResponseObserver = mtsAPI.GetSessionID("token/login", AppConstants.PARAMS + "");
          mainResponseObserver.subscribeOn(Schedulers.io())
                  .observeOn(AndroidSchedulers.mainThread())
                  .subscribe(new Observer&lt;MainResponse&gt;() {
                      @Override
                      public void onSubscribe(Disposable d) {
  
                      }
  
                      @Override
                      public void onNext(MainResponse mainResponse) {
                          Log.v("Response", mainResponse.getEid());
                          if (mainResponse.getEid()==null) {
                              msessionId.postValue("Token Error");
                          }
                          else {
                              msessionId.postValue("1");
                              rUserDetails.setSid(mainResponse.getEid());
  
                 rUserDetails.setResourcId(mainResponse.getUserVO().getBact());
                              insert(rUserDetails);
                          }
                      }
  
                      @Override
                      public void onError(Throwable e) {
  
                      }
  
                      @Override
                      public void onComplete() {
  
                      }
                  });
     }
     else {
          msessionId.postValue("E");
      }
      return msessionId;
  
  }
  </code></pre>
  
  <p>I am stuck on the part where i check if the data of the user is in the Room DB. If in room DB it returns UserDetails which is a mutable live data.</p>
  
  <p>I have tested out the DB. It inserts successfully and was reading successfully to when i tested them our separately.</p>
  
  <p>Dao</p>
  
  <pre><code>@Dao
  public interface UserLoginDetailsDao {
      @Insert(onConflict = REPLACE)
      void save(UserLoginDetails user);
      @Query("SELECT sid, Username, Password,ResourcId,Token  FROM 
      UserLogins_tbl 
      WHERE Username = :userId")
      LiveData&lt;UserLoginDetails&gt; loadUserDetails(String userId);
  }
  </code></pre>
  
  <p>With Above code i get Cant invoke Null.... on UserDetails.getvalue.getToken</p>