title: Error in creating instance of a class viewModel
body: <p>I am just trying to learn Room. So I created a sample application using the guidelines provided by Google in <a href="https://codelabs.developers.google.com/codelabs/android-room-with-a-view/#0" rel="nofollow noreferrer">this</a>. I am getting a following error</p>
  
  <pre><code>java.lang.RuntimeException: Unable to start activity ComponentInfo{com.brahma/com.brahma.ui.SignUpActivity}: java.lang.RuntimeException: Cannot create an instance of class com.brahma.viewModel.UserViewModel
          at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2778)
          at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
          at android.app.ActivityThread.-wrap11(Unknown Source:0)
          at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
          at android.os.Handler.dispatchMessage(Handler.java:106)
          at android.os.Looper.loop(Looper.java:164)
          at android.app.ActivityThread.main(ActivityThread.java:6501)
          at java.lang.reflect.Method.invoke(Native Method)
          at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
       Caused by: java.lang.RuntimeException: Cannot create an instance of class com.brahma.viewModel.UserViewModel
          at android.arch.lifecycle.ViewModelProvider$AndroidViewModelFactory.create(ViewModelProvider.java:207)
          at android.arch.lifecycle.ViewModelProvider.get(ViewModelProvider.java:134)
          at android.arch.lifecycle.ViewModelProvider.get(ViewModelProvider.java:102)
          at com.brahma.ui.SignUpActivity.onCreate(SignUpActivity.java:72)
          at android.app.Activity.performCreate(Activity.java:7036)
          at android.app.Activity.performCreate(Activity.java:7027)
          at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1215)
          at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2731)
          at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856) 
          at android.app.ActivityThread.-wrap11(Unknown Source:0) 
          at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589) 
          at android.os.Handler.dispatchMessage(Handler.java:106) 
          at android.os.Looper.loop(Looper.java:164) 
          at android.app.ActivityThread.main(ActivityThread.java:6501) 
          at java.lang.reflect.Method.invoke(Native Method) 
          at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438) 
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807) 
       Caused by: java.lang.reflect.InvocationTargetException
          at java.lang.reflect.Constructor.newInstance0(Native Method)
          at java.lang.reflect.Constructor.newInstance(Constructor.java:334)
          at android.arch.lifecycle.ViewModelProvider$AndroidViewModelFactory.create(ViewModelProvider.java:199)
          at android.arch.lifecycle.ViewModelProvider.get(ViewModelProvider.java:134) 
          at android.arch.lifecycle.ViewModelProvider.get(ViewModelProvider.java:102) 
          at com.brahma.ui.SignUpActivity.onCreate(SignUpActivity.java:72) 
          at android.app.Activity.performCreate(Activity.java:7036) 
          at android.app.Activity.performCreate(Activity.java:7027) 
          at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1215) 
          at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2731) 
          at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856) 
          at android.app.ActivityThread.-wrap11(Unknown Source:0) 
          at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589) 
          at android.os.Handler.dispatchMessage(Handler.java:106) 
          at android.os.Looper.loop(Looper.java:164) 
          at android.app.ActivityThread.main(ActivityThread.java:6501) 
          at java.lang.reflect.Method.invoke(Native Method) 
          at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438) 
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807) 
       Caused by: java.lang.IllegalStateException: Cannot access database on the main thread since it may potentially lock the UI for a long period of time.
          at android.arch.persistence.room.RoomDatabase.assertNotMainThread(RoomDatabase.java:164)
          at android.arch.persistence.room.RoomDatabase.query(RoomDatabase.java:192)
          at com.brahma.Room.UserDao_Impl.getUser(UserDao_Impl.java:56)
          at com.brahma.repository.UserRepository.&lt;init&gt;(UserRepository.java:18)
          at com.brahma.viewModel.UserViewModel.&lt;init&gt;(UserViewModel.java:17)
          at java.lang.reflect.Constructor.newInstance0(Native Method) 
          at java.lang.reflect.Constructor.newInstance(Constructor.java:334) 
          at android.arch.lifecycle.ViewModelProvider$AndroidViewModelFactory.create(ViewModelProvider.java:199) 
          at android.arch.lifecycle.ViewModelProvider.get(ViewModelProvider.java:134) 
          at android.arch.lifecycle.ViewModelProvider.get(ViewModelProvider.java:102) 
          at com.brahma.ui.SignUpActivity.onCreate(SignUpActivity.java:72) 
          at android.app.Activity.performCreate(Activity.java:7036) 
          at android.app.Activity.performCreate(Activity.java:7027) 
          at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1215) 
          at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2731) 
          at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856) 
          at android.app.ActivityThread.-wrap11(Unknown Source:0) 
          at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589) 
          at android.os.Handler.dispatchMessage(Handler.java:106) 
          at android.os.Looper.loop(Looper.java:164) 
          at android.app.ActivityThread.main(ActivityThread.java:6501) 
          at java.lang.reflect.Method.invoke(Native Method) 
          at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438) 
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807) 
  </code></pre>
  
  <p>I tried to look for the solution on internet but didn't get the success. The  solutions available on stackOverflow ask to make the constructor public of viewModel, which my costructor already is.</p>
  
  <p>Here is my viewModel:</p>
  
  <pre><code>public class UserViewModel extends AndroidViewModel{
  
      private UserRepository mUserRepository;
      private User mUserInfo;
  
      public UserViewModel( Application application) {
          super(application);
          mUserRepository = new UserRepository(application);
          mUserInfo = mUserRepository.getmUserInfo();
      }
  
  
      public User getUserInfo(){
          return mUserInfo;
      }
      public void insert(User user){
          mUserRepository.insert(user);
      }
  }
  </code></pre>
  
  <p>Below is my activity where I am instantiating the viewModel:</p>
  
  <pre><code>protected void onCreate(@Nullable Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          FacebookSdk.sdkInitialize(getApplicationContext());
          setContentView(R.layout.activity_sign_up);
          AppEventsLogger.activateApp(this, getString(R.string.facebook_app_id));
          initViews();
  
          mUserViewModel = ViewModelProviders.of(this).get(UserViewModel.class);
  
          callbackManager = CallbackManager.Factory.create();
          mGoogleSignUp.setOnClickListener(this);
          mFacebookSignUp.setOnClickListener(this);
          initGoogleApiClient();
      }
  </code></pre>
  
  <p>I have no idea what I am doing wrong.</p>