Attempt to invoke virtual method 'android.content.Context android.content.Context.getApplicationContext()' on a null object reference

It’s because in MainFragment, you’re passing in a brand new Application class to your factory. Instead, replace this line:

val factory = MyViewModelFactory(Application(),"","")

With this:

val factory = MyViewModelFactory(activity?.application,"","")

Also as a tip make sure that you surround all code block with triple backticks like this:
```
// Code goes here
```
Which shows up like this:

// Code goes here