Explore all Android Architecture open source software, libraries, packages, source code, cloud functions and APIs.

Popular New Releases in Android Architecture

flexbox-layout

3.0.0

ReactiveLiveData

1.0.1

coin-collection-android-US

Release v3.4.0

Popular Libraries in Android Architecture

flexbox-layout

by google doticonkotlindoticon

star image 16747 doticonApache-2.0

Flexbox for Android

permissions-samples

by android doticonkotlindoticon

star image 234 doticonApache-2.0

Multiple samples showing the best practices in permissions on Android.

ReactiveLiveData

by musichin doticonkotlindoticon

star image 81 doticonMIT

Transformation functions for LiveData

Dagger-2-For-Android-Beginners

by Hariofspades doticonjavadoticon

star image 76 doticon

For the blog, Dagger 2 for Android Beginners

elm-architecture-android

by glung doticonkotlindoticon

star image 59 doticonMIT

An example of the ELM architecture on Android using Kotlin with Anko

DataBindingExample

by stfalcon-studio doticonjavadoticon

star image 57 doticon

Sample project for the https://stfalcon.com/en/blog/post/faster-android-apps-with-databinding blogpost

android-livecode-demo

by yigit doticonjavadoticon

star image 49 doticon

repo for the android live code event, Feb 5, 2014

play-framework-kotlin

by Karumi doticonkotlindoticon

star image 48 doticon

This repository is to show how to create an Play Framework project using Kotlin

chip-atlas

by inutano doticonjavascriptdoticon

star image 41 doticonMIT

ChIP-Atlas: Browse and analyze all public ChIP/DNase-seq data on your browser

Trending New libraries in Android Architecture

Blog-Sample-Android

by KimReady doticonkotlindoticon

star image 4 doticon

A collection of android-samples posted on a blog.

cchads

by gek169 doticoncdoticon

star image 2 doticon

Main code repository for small free software projects done by or used by the C Chads.

prismvpn-android

by personal-security doticonjavadoticon

star image 0 doticonGPL-3.0

Simple android vpn app

Top Authors in Android Architecture

1

ITMSystemAD

1 Libraries

star icon2

2

LorcanMcVeigh

1 Libraries

star icon2

3

maitesin

1 Libraries

star icon27

4

avarteq

1 Libraries

star icon4

5

vorburger

1 Libraries

star icon2

6

Karumi

1 Libraries

star icon48

7

yanaga-samples

1 Libraries

star icon7

8

BigOcto

1 Libraries

star icon3

9

laohehe

1 Libraries

star icon4

10

fajaragungpramana

1 Libraries

star icon4

1

1 Libraries

star icon2

2

1 Libraries

star icon2

3

1 Libraries

star icon27

4

1 Libraries

star icon4

5

1 Libraries

star icon2

6

1 Libraries

star icon48

7

1 Libraries

star icon7

8

1 Libraries

star icon3

9

1 Libraries

star icon4

10

1 Libraries

star icon4

Trending Kits in Android Architecture

No Trending Kits are available at this moment for Android Architecture

Trending Discussions on Android Architecture

How are Android activities handled with Jetpack Compose and Compose Navigation?

SetTheme to an activity with PreferencesDataStore

What is the best practice for starting a new thread when using Firebase Realtime Database?

Get second last value in each row of dataframe, R

Cannot create an instance of ViewModel Class

Android MVVM: how to avoid multiple livedata triggers when data from network did not change

Can I add Observer inside Observer? I actually tried but inner observers not working properly. Sometimes one of them work, sometimes no one work

Why I am facing threading issues despite using room database TransactionExecutor?

Where to Save ViewModel State in Android's MVVM?

Android (Kotlin): Type mismatch in Observer

QUESTION

How are Android activities handled with Jetpack Compose and Compose Navigation?

Asked 2021-Dec-15 at 03:26

I'm currently studying Jetpack Compose in an attempt to build a feature-rich application using modern Android architecture components. Traditionally, each screen (or navigation unit) in my application would be either an activity or a fragment, each with its own lifecycle bindings, but with Jetpack Compose and the Compose Navigation library, I would do something like this:

MainActivity.kt:

1class MainActivity : ComponentActivity() {
2    override fun onCreate(savedInstanceState: Bundle?) {
3        super.onCreate(savedInstanceState)
4        setContent {
5            val navController = rememberNavController()
6
7            NavHost(navController = navController, startDestination = "main") {
8                composable("main") { MainScreen(navController) }
9                // More composable calls
10            }
11        }
12    }
13}
14
15

Where MainScreen is just a composable. My questions are:

  • What is the equivalent here of a "lifecycle" for this composable? Say I want to perform some action when the screen is loaded, when it is destroyed etc. This is perhaps more relevant to the case where I have more screens and navigation between them
  • Is there some way to integrate between Compose and standard activities? That is, define activities for screens as you would, with each activity being a ComponentActivity and defining its own composable layout? Is this discouraged for some reason?

ANSWER

Answered 2021-Aug-29 at 04:50

The Compose application is designed to be used in a single-activity architecture with no fragments.

You can still have multiple activities or fragments and use setContent in each of them, but in this case the transfer of data between activities falls on your shoulders. Use this approach if you're adding new Compose screens to an existing application built the old way.

But with Compose, it's much easier to do all the navigation within a single activity using Compose Navigation. Much less code, better performance due to no unnecessary code layers, easy to transfer data, etc.

To work with the view lifecycle, check out compose side-effects:

  1. LaunchedEffect can be used to execute an action when the view appears. It also runs on a coroutine context that is bound to the current composable: you can easily run suspend functions, and when the view disappears from view hierarchy - the coroutine will be canceled.
  2. DisposableEffect can be used to subscribe to/unsubscribe from callbacks.

When you rotate the screen, all effects will restart no matter which key you passed.

1class MainActivity : ComponentActivity() {
2    override fun onCreate(savedInstanceState: Bundle?) {
3        super.onCreate(savedInstanceState)
4        setContent {
5            val navController = rememberNavController()
6
7            NavHost(navController = navController, startDestination = "main") {
8                composable("main") { MainScreen(navController) }
9                // More composable calls
10            }
11        }
12    }
13}
14
15@Composable
16fun MainScreen(navController: NavController) {
17    LaunchedEffect(Unit) {
18        println("LaunchedEffect: entered main")
19        var i = 0
20        // Just an example of coroutines usage
21        // don't use this way to track screen disappearance
22        // DisposableEffect is better for this
23        try {
24            while (true) {
25                delay(1000)
26                println("LaunchedEffect: ${i++} sec passed")
27            }
28        } catch (cancel: CancellationException) {
29            println("LaunchedEffect: job cancelled")
30        }
31    }
32    DisposableEffect(Unit) {
33        println("DisposableEffect: entered main")
34        onDispose {
35            println("DisposableEffect: exited main")
36        }
37    }
38}
39

Also note that in both cases, and in many other cases in compose, you pass key to these functions. This helps compose understand when the value should be recomputed. In my example it is Unit, which means that it won't change until the view is gone. But if you create a remember value, use another dynamic value from the view model, or pass another argument to composable, you can pass it as a key, this will cancel the current LaunchedEffect job and call onDispose for DisposableEffect, and your job will be restarted with the updated key value. You can pass as many keys as you want.

Read more about the state in Compose in documentation.

Source https://stackoverflow.com/questions/68962458

QUESTION

SetTheme to an activity with PreferencesDataStore

Asked 2021-Oct-12 at 10:27

I have switched my app from using SharedPreferences to PreferencesDataStore. I have also implemented a dark mode and several themes inside my app. For theming, I basically rely in each activity on this code:

1    val themePreferences = getSharedPreferences("THEME_PREFERENCES", MODE_PRIVATE)
2    val settingsPreferences = getSharedPreferences("SETTINGS_PREFERENCES", MODE_PRIVATE)
3    darkMode = settingsPreferences.getBoolean("darkMode", false)
4
5    setTheme(when (darkMode) {
6        true -> themePreferences.getInt("themeDark", R.style.AppThemeDark)
7        false -> themePreferences.getInt("themeLight", R.style.AppThemeLight)
8    })
9

The selected theme gets stored as an Integer, each once for the light mode as well as the dark mode. Now, I also want to adopt this section of my code. I get my darkMode boolean from my dataStore repository like this:

1    val themePreferences = getSharedPreferences("THEME_PREFERENCES", MODE_PRIVATE)
2    val settingsPreferences = getSharedPreferences("SETTINGS_PREFERENCES", MODE_PRIVATE)
3    darkMode = settingsPreferences.getBoolean("darkMode", false)
4
5    setTheme(when (darkMode) {
6        true -> themePreferences.getInt("themeDark", R.style.AppThemeDark)
7        false -> themePreferences.getInt("themeLight", R.style.AppThemeLight)
8    })
9viewModel.storedDarkMode.observe(this) { darkMode = it }
10

If I work inside the observe(this) { ... } of the LiveData object it won't work.

Now, how can I change my code snippet shown above to PreferencesDataStore? Or is it actually better e.g. to make a separate class in order to observe the values from there? If yes, how could something like that look like? Or do you know some good example code following Android Architecture including custom themes with a dark mode where I can look at?

I am still learning a lot, any help for better understanding this is much appreciated!

Best regards, Markus

Edit:

1    val themePreferences = getSharedPreferences("THEME_PREFERENCES", MODE_PRIVATE)
2    val settingsPreferences = getSharedPreferences("SETTINGS_PREFERENCES", MODE_PRIVATE)
3    darkMode = settingsPreferences.getBoolean("darkMode", false)
4
5    setTheme(when (darkMode) {
6        true -> themePreferences.getInt("themeDark", R.style.AppThemeDark)
7        false -> themePreferences.getInt("themeLight", R.style.AppThemeLight)
8    })
9viewModel.storedDarkMode.observe(this) { darkMode = it }
10runBlocking {
11        val darkMode = viewModel.darkModeFlow.first()
12        setTheme(when (darkMode) {
13            true -> viewModel.themeDarkFlow.first()
14            false -> viewModel.themeLightFlow.first()
15        })
16    }
17

ANSWER

Answered 2021-Sep-30 at 05:14

I don't know if it is best practice or not, but I use runBlocking to get theme data from dataStore. It is always recommended that, we should never use runBlocking in our production code.

1    val themePreferences = getSharedPreferences("THEME_PREFERENCES", MODE_PRIVATE)
2    val settingsPreferences = getSharedPreferences("SETTINGS_PREFERENCES", MODE_PRIVATE)
3    darkMode = settingsPreferences.getBoolean("darkMode", false)
4
5    setTheme(when (darkMode) {
6        true -> themePreferences.getInt("themeDark", R.style.AppThemeDark)
7        false -> themePreferences.getInt("themeLight", R.style.AppThemeLight)
8    })
9viewModel.storedDarkMode.observe(this) { darkMode = it }
10runBlocking {
11        val darkMode = viewModel.darkModeFlow.first()
12        setTheme(when (darkMode) {
13            true -> viewModel.themeDarkFlow.first()
14            false -> viewModel.themeLightFlow.first()
15        })
16    }
17val preferences = runBlocking {
18    mainActivityViewModel.preferencesFlow.first()
19}
20setAppTheme(preferences.currentTheme)
21binding = ActivityMainBinding.inflate(layoutInflater)
22

In setAppTheme method

1    val themePreferences = getSharedPreferences("THEME_PREFERENCES", MODE_PRIVATE)
2    val settingsPreferences = getSharedPreferences("SETTINGS_PREFERENCES", MODE_PRIVATE)
3    darkMode = settingsPreferences.getBoolean("darkMode", false)
4
5    setTheme(when (darkMode) {
6        true -> themePreferences.getInt("themeDark", R.style.AppThemeDark)
7        false -> themePreferences.getInt("themeLight", R.style.AppThemeLight)
8    })
9viewModel.storedDarkMode.observe(this) { darkMode = it }
10runBlocking {
11        val darkMode = viewModel.darkModeFlow.first()
12        setTheme(when (darkMode) {
13            true -> viewModel.themeDarkFlow.first()
14            false -> viewModel.themeLightFlow.first()
15        })
16    }
17val preferences = runBlocking {
18    mainActivityViewModel.preferencesFlow.first()
19}
20setAppTheme(preferences.currentTheme)
21binding = ActivityMainBinding.inflate(layoutInflater)
22private fun setAppTheme(theme: Boolean) {
23        mainActivityViewModel.darkMode = theme
24        //set your theme here
25    }
26

Now observe preferencesFlow for any change in theme value, and if the theme is changed then recreate()

1    val themePreferences = getSharedPreferences("THEME_PREFERENCES", MODE_PRIVATE)
2    val settingsPreferences = getSharedPreferences("SETTINGS_PREFERENCES", MODE_PRIVATE)
3    darkMode = settingsPreferences.getBoolean("darkMode", false)
4
5    setTheme(when (darkMode) {
6        true -> themePreferences.getInt("themeDark", R.style.AppThemeDark)
7        false -> themePreferences.getInt("themeLight", R.style.AppThemeLight)
8    })
9viewModel.storedDarkMode.observe(this) { darkMode = it }
10runBlocking {
11        val darkMode = viewModel.darkModeFlow.first()
12        setTheme(when (darkMode) {
13            true -> viewModel.themeDarkFlow.first()
14            false -> viewModel.themeLightFlow.first()
15        })
16    }
17val preferences = runBlocking {
18    mainActivityViewModel.preferencesFlow.first()
19}
20setAppTheme(preferences.currentTheme)
21binding = ActivityMainBinding.inflate(layoutInflater)
22private fun setAppTheme(theme: Boolean) {
23        mainActivityViewModel.darkMode = theme
24        //set your theme here
25    }
26mainActivityViewModel.preferencesLiveData.observe(this) {
27        if (it.currentTheme != mainActivityViewModel.selectedTheme) {
28            recreate()
29        }
30    }
31

As we can't load our UI, without getting the theme. It seemed right to use runBlocking.

Source https://stackoverflow.com/questions/69376689

QUESTION

What is the best practice for starting a new thread when using Firebase Realtime Database?

Asked 2021-Sep-05 at 23:29

I'm following along this blog for using Android Architecture Components with Firebase Realtime Database. Currently, I am at the part of the blog where I move the LiveData callbacks to onChanged() onto a different thread.

This is what I have (the Kotlin equivalent of the Java code from the blog):

1private val uid = Firebase.auth.currentUser!!.uid
2private val USERS_REF: DatabaseReference = FirebaseDatabase.getInstance().getReference("/users/$uid")
3private val liveData: FirebaseQueryLiveData = FirebaseQueryLiveData(USERS_REF)
4private val usersLiveData: MediatorLiveData<Users> = MediatorLiveData()
5
6fun UsersViewModel() {
7    usersLiveData.addSource(liveData, object : Observer<DataSnapshot> {
8        override fun onChanged(dataSnapshot: DataSnapshot?) {
9            if (dataSnapshot != null) {
10                Thread(Runnable() {
11                    run() {
12                        usersLiveData.postValue(dataSnapshot.getValue(Users::class.java))
13                    }
14                }).start()
15            } else {
16                usersLiveData.value = null
17            }
18        }
19    })
20}
21

In the blog, it states that the way it has shown to start up a new thread is not considered the "best practice" for starting another thread in a production app. The suggestion is to use an Executor with a pool of reusable threads for a job like this.

How do I modify the current Runnable Thread so that it uses an optimal practice for starting a new thread?

ANSWER

Answered 2021-Sep-05 at 23:28

You don't need a new thread at all here. Just remove it.

postValue() is asynchronous and doesn't block anything. You can call it safely on the main thread. Any LiveData observers will get the value immediately after the database callback completes.

Source https://stackoverflow.com/questions/69067058

QUESTION

Get second last value in each row of dataframe, R

Asked 2021-May-14 at 14:45

I am trying to get the second last value in each row of a data frame, meaning the first job a person has had. (Job1_latest is the most recent job and people had a different number of jobs in the past and I want to get the first one). I managed to get the last value per row with the code below:

first_job <- function(x) tail(x[!is.na(x)], 1)

first_job <- apply(data, 1, first_job)

1structure(list(Index = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 
213, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 
329, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 
445, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59), 
5    FromJob = c(&quot;Senior Machine Learning Engineer&quot;, &quot;Senior Machine Learning Engineer&quot;, 
6    &quot;Senior Machine Learning Engineer&quot;, &quot;Senior Machine Learning Engineer&quot;, 
7    &quot;Senior Machine Learning Engineer&quot;, &quot;Python Data Engineer (m/w/d)&quot;, 
8    &quot;Python Data Engineer (m/w/d)&quot;, &quot;Python Data Engineer (m/w/d)&quot;, 
9    &quot;Lead Backend Developer (f/m/d)&quot;, &quot;Lead Backend Developer (f/m/d)&quot;, 
10    &quot;Lead Backend Developer (f/m/d)&quot;, &quot;Lead Backend Developer (f/m/d)&quot;, 
11    &quot;Python Data Engineer (m/w/d)&quot;, &quot;Python Data Engineer (m/w/d)&quot;, 
12    &quot;Lead Developer&quot;, &quot;Lead Developer&quot;, &quot;Lead Developer&quot;, &quot;Lead Developer&quot;, 
13    &quot;Lead Developer&quot;, &quot;Lead Developer&quot;, &quot;Team Lead Software Development&quot;, 
14    &quot;(Senior) Frontend Engineer&quot;, &quot;(Senior) Frontend Engineer&quot;, 
15    &quot;(Senior) Frontend Engineer&quot;, &quot;(Senior) Frontend Engineer&quot;, 
16    &quot;(Senior) Frontend Engineer&quot;, &quot;(Senior) Frontend Engineer&quot;, 
17    &quot;Data Scientist&quot;, &quot;Data Scientist&quot;, &quot;Senior Backend (Java) Engineer&quot;, 
18    &quot;Senior Backend (Java) Engineer&quot;, &quot;Senior Backend (Java) Engineer&quot;, 
19    &quot;Lead Developer&quot;, &quot;Mobile Software Engineer&quot;, &quot;Mobile Software Engineer&quot;, 
20    &quot;Mobile Software Engineer&quot;, &quot;Mobile Software Engineer&quot;, &quot;Mobile Software Engineer&quot;, 
21    &quot;Mobile Software Engineer&quot;, &quot;Mobile Software Engineer&quot;, &quot;Mobile Software Engineer&quot;, 
22    &quot;Mobile Software Engineer&quot;, &quot;Mobile Software Engineer&quot;, &quot;Mobile Software Engineer&quot;, 
23    &quot;Mobile Software Engineer&quot;, &quot;Lead UI/UX Designer&quot;, &quot;Lead UI/UX Designer&quot;, 
24    &quot;Lead UI/UX Designer&quot;, &quot;Lead UI/UX Designer&quot;, &quot;Head of Software Development&quot;, 
25    &quot;Head of Software Development&quot;, &quot;Head of Software Development&quot;, 
26    &quot;Head of Software Development&quot;, &quot;Head of Software Development&quot;, 
27    &quot;Head of Software Development&quot;, &quot;Head of Software Development&quot;, 
28    &quot;Head of Software Development&quot;, &quot;Jnuior Fullstack Developer&quot;, 
29    NA), Highest_education_achieved = c(&quot;PhD&quot;, &quot;MSc Computer Science&quot;, 
30    &quot;MSc&quot;, &quot;MBA&quot;, &quot;MSc&quot;, &quot;MSc&quot;, &quot;MSc&quot;, &quot;MSc Communication and Media Engineering&quot;, 
31    &quot;High School&quot;, &quot;BSc Informatics&quot;, &quot;BSc Software engineering&quot;, 
32    NA, &quot;MSc in Electronic Engineering&quot;, &quot;MSc in Communication and Media Engineering&quot;, 
33    &quot;BSc in Computer Engineering&quot;, &quot;BSc in Technology&quot;, &quot;MSc in Computer Science&quot;, 
34    &quot;BSc in Automatic Control System&quot;, &quot;Dipl. Wirtschaftsinformatik&quot;, 
35    &quot;MCs Computer Science&quot;, &quot;Dipl. Ing. in Software Development - Economics&quot;, 
36    &quot;MSc in Computer Science&quot;, &quot;BSc. in Information Technology&quot;, 
37    &quot;MSc in Big Data and Business Analyst&quot;, &quot;MSc. in Computer Science&quot;, 
38    &quot;Dipl.&quot;, &quot;BSc.&quot;, &quot;MSc. in Scientific Computing and Biomechanics&quot;, 
39    &quot;MSc. in Computational Engineering&quot;, &quot;MSc. in Information Technology&quot;, 
40    &quot;MSc. in Computer Science&quot;, &quot;MSc. in Informatics&quot;, &quot;BSc.&quot;, 
41    &quot;BSc.&quot;, &quot;BSc.&quot;, &quot;BSc.&quot;, &quot;BSc.&quot;, &quot;BSc.&quot;, &quot;BSc.&quot;, &quot;BSc.&quot;, &quot;Highschool&quot;, 
42    &quot;BSc.&quot;, &quot;BSc.&quot;, &quot;Highschool&quot;, &quot;BSc.&quot;, &quot;MCs.&quot;, &quot;BSc.&quot;, &quot;BSc.&quot;, 
43    &quot;BSc.&quot;, &quot;MCs.&quot;, &quot;BSc.&quot;, &quot;Dipl.&quot;, &quot;BSc.&quot;, &quot;BSc.&quot;, &quot;BSc.&quot;, 
44    &quot;BSc.&quot;, &quot;MSc.&quot;, &quot;BSc.&quot;, NA), Skills = c(&quot;Machine Learning, Mathematical Modeling, Scientific Computing, Linux, python, numpy, scipy, scikit-learn, keras, pandas, javascript, react.js, AWS, Lambda, EMR, EC2, S3, Glue, CloudFormation, git,  Image recognition, deep learning, Natural language processing, Big data integration, cloud migration, Azure, Fortran, OpenFOAM, mercurial&quot;, 
45    &quot;Java, AngularJS, frontend, backend, Azure, data collection, modelbuilding, evaluation, deployment, serving and computing online metrics,  Apache Spark, AWS Sagemaker, Airflow, MLflow, MLOps&quot;, 
46    &quot;Biometrics, Machine Learning, Pattern Recognition, AI, scrum, matlab, C++, Azure, logistics&quot;, 
47    &quot;Databricks, Spark, Airflow, AWS Sagemaker, Other AWS Services, Docker, Microstrategy, Presto, Python, PL/SQL, JavaScript, Shell Scripting, BigQuery (Google), Hadoop, Exasol, Kafka&quot;, 
48    &quot;Spark, Tensorflow &amp;TFX, Kubeflow, BigQuery, Apache Beam (Dataflow), Google Cloud Platform&quot;, 
49    &quot;PythonC++, C, OpenCV, OpenCL, MatLab, TensorFlow/PyTorch, Caffe/Keras, Scikit-learn, Pandas/NumPy, Seaborn/Matplotlib, NLTK/spaCy, Computer Vision, Machine Learning, NLP, Linear/LogisticRegression, Naive Bayes/PCA, SVM/K Means, RandomForest, CNN/LSTM/GRU, Reinforcement Learning&quot;, 
50    &quot;Microsoft SQL Server, Hadoop,SQL Server Management Studio, VisualStudio(DataTools), PyCharm, Sublime text 3, SSIS, python, C#, \nC++, Html/Css, Java,T-SQL, git&quot;, 
51    &quot;Keras, TensorFlow, scikit-learn, NLTK, OpenCV, NumPy, pandas,Python, Java, PHP, HTML, CSS, JavaScript, Angular, React, jQuery, Bootstrap, Flask, SQL, MongoDB, Git, Docker&quot;, 
52    &quot;ElasticSearch, OOP, NoSQL, SQL, Docker, Kibana, Git, Unittest, Openshift&quot;, 
53    &quot;PHP, Java Script, CSS, (X)HTML, MySQL., NodeJS&quot;, &quot;JavaScript (Vue.js, React, jQuery), Node.js (Express), PHP (Yii, Laravel, Symfony), JAVA (Spring Boot), .NET C#, SQL(postregsql, mysql), Elastic, MongoDB, HTML + CSS, Sketch, InVision Studio&quot;, 
54    NA, &quot;Python, C++, HTML/CSS, Java, C#, T-SQL, Microsoft SQL Server, Hadoop, Pycharm, Sublimetext 3, SISS, Git,Liquid Planner,&quot;, 
55    &quot;Keras, TensorFlow, scikit-Learn, NLTK, openCV, NumPy, pandas, Python, Java, PHP, HTML, JavaScript,CSS, Angular, React, jQuery, Bootstrap, Flask, SQL, MonoDB, Git, Android, PhoneGap, Docker&quot;, 
56    &quot;Java, PL/SQL, HTML, JavaScript, PHP, Bash, AngularJs, ReactJs, Python, Weblogic, Jboss, Tomcat, Jetty, Apache, IIS, Unix, Windows, Oracle 8i, 9i, 10g, MySql, MariaDB, PostgrwSql, MS Sql Server, GIT, Mercury, Jira&quot;, 
57    &quot;JavaScript, AngularJs, Angular Next, jQuery, RequireJS, React, WebPack, Typescript, Node, PWA, Socket Programming, Kong,&quot;, 
58    &quot;GIT, SME, API's, iOS, UI, Mobile application, SVN, Epic, Apple, SAML,&quot;, 
59    &quot;Kotlin, Java, JavaScript, Typescript, Pytion ML, AI, Spring, NoSQL, SQL, Microservices, AWS, Azure, Angular9, React, Kafka, Jenkins, Cloud, Rancher, K8s, Cloud foundry, MSSQL, Elas, Tensorflow, Boot, Teras, Hibernite, RabbitMQ, JUnit, AWS SQS, Docker, C++, STL, XML, Linux, Bash,&quot;, 
60    &quot;Scrum, Code Reviews, JIRA, Mantis, Kanban, Trello, Java, Kotlin, Typescript, Groovy, JavaScript, Delphi, Openshift, Kubernetes, Docker, Azure, Open Telekom Cloud, CosmosDB, Heroku, REST, SOAP, XMPP, NATS, JMS, ActiveMQ, Gatling, Mocktesting, Mockito, EasyMock, Cucumber, Angular 8, React, GWT, JSF, JSP, Struts, Spring Boot, JEE, Hibernate, JPA, MongoDB, Oracle, Postgres, CosmosDB, MySQL, DB2, SQL-Tuning, Maven, Ant, Gradle, GIT, SVN, CVS, BIRT, JasperReports, MicroStrategy, Maven,&quot;, 
61    &quot;Kotlin, Java 11, Docker, AWS, GCP, Kubernetes,Neo-4j, Solr, Spring-boot, Postgres, Hibernate, Flyway, sendGrit, Gradl, rxJava, Freemaker, Grafana, Prometheus,Oauth 2, Spring-gateway, Microservices, AWS, Amazon EMR, DynamoDB, S3, Hive, hdfs, storm, kafka, reactive programming, spring-cloud, groovy, elasticsearch, hystrix, ribbon, eureka, API, java 8, grunt, bamboo, jenkins, JavaScript, Junit, jbpm, jmx, C++, j2ee, servlet,&quot;, 
62    &quot;Scrum, SAP, NetWeaver 7.40&quot;, &quot;CSS. Html, Bootstrap, Php, MySQL, JavaScript, Wordpress, Typo 3, Google Analytics, Google Adwords, React, GatsbyJS, Nextjs, Flutter, Postgres, AWS, Docker, Google Cloud Platform,&quot;, 
63    &quot;Node JS, JavaScript, ES6, CSS, PHP, XML, JQuery, Lambda, Appsync, React, JS, HTML5, CSS3, Bootstrap, REST web services, Microservices, JSON, Elasticsearch, Java, React JS, AWS Server, MAMP, Maven, Laravel, Codeigniter, MySQL, Dynamo DB, SQLite, Oracle, MS SQL, MAC, UNIX, Windows, Git, AWS-EC2, S3, Cloud Formation, Cloudwatch, SNS, PhpStorm, WebSorm, Visual Studio Code, Eclipse, Netbeans, Android Studio&quot;, 
64    &quot;C, C++, Java, J2EE, Dotnet, Angular, React, JS, JavaScript, Query, CSS, HTML, Microsoft SQL Server, GIT, React JS with Redux, Vue JS, CSS3, Bootstrap, Media query, AEM, Jest test, Python, Tabeleau, AWS, Miro&quot;, 
65    &quot;JavaScript, ReactJs, TypeScript, Python, C++, HTML, ASP, C#&quot;, 
66    &quot;SPA, TypeScript, React Hooks, Jest, Lerna, React Query, Azure DevOps, Storybook, RxJx, Socket.io, OpenAPI, SCSS,&quot;, 
67    &quot;JavaScript, React JS, Flow, Redux, React SSR, urql graphql client, Java 11, HTML5, CSSS3, JavaScript (ES6+), TypeScript, jQuery, AJAX, webpack, NodeJS, PHP, Express, MongoDB, SASS, Heroku, Linux, Hetzner, Git, AngularJS,&quot;, 
68    &quot;Linux, Windows, MS Office, Libre office, Python, SQL, Bash, C/C++, MATLAB, NumPy, SciPy, pandas, SciKit-Learn, statsmodels, Keras, TensorFlow, Flask, Matplotlib, Seaborn, Tableau, ParaView, Tecplot, Inkscape, GIMP, PyCharm, jupyter, Eclipse, Visual Studio, Git, Docker, Poetry, Pytest, Unittest, Pylint, Pre-commit&quot;, 
69    &quot;Python, C/C++, SQL, MySQL, Numpy, Pandas, Scipy, Scikit-Learn, Keras, Tensorflow, Theano, PyTorch, Visual Studio, Pycharm, Jupyter Notebook, Vscode, PowerBi, MS Office, Sourcetree, Jira, Git, Linux, Mac, Windows&quot;, 
70    &quot;NPM, Webpack, Bower, Gruntjs, Gulp, JavaScript, Angular, CSS, Animation, Angular-animation, TypeScript, ReactJS, Node.js, Lombok, Vue.js, Visual Studio, HTML, Maven, Redux, Chart.js, Kotlin,&quot;, 
71    &quot;Java. Web Services, Design Patterns, Agile Methodologies, Spring Hibernate, JSF, JUnit, Maven Eclipse, SQL, XML, Linux, Websphere, Tomcat, jQuery, Ant, JDBC, Subversion, JavaScript, CSS, JPA, Git, Jenkins, REST, services, AJAX, Glassfish, Java Enterprise Edition, Apache, Lucene, Artifactory,&quot;, 
72    &quot;Java, HTML, Perl, Programming, SQL, JavaScript, CSS, Oracle, C++, Linux, CSS, PHP, C#, Ruby, C&quot;, 
73    NA, &quot;Jira, Git, Scrum, Agile, Retrofit, Picasso, Volley, RESTful, HTTP, JSON, Asyns-task, Dagger2, MVVM Architecture, API, SQLite, Pandas, NumPy,&quot;, 
74    &quot;Kotlin, MVVM Archtiecture, Firebase, Google-Services, Git, Retrofit, JSON, Material Design UI, Constrains Layout Animations, Jira, Figma, Zeplin, Agile, Scrum&quot;, 
75    &quot;C++, Java, MVC Design, AdMob, Google Maps API Keys, Retrofit, Gson, SQLite, Picasso, Google Vision, Play Services, SQL, iOS Develpment, JSON, C#, XML, Android&quot;, 
76    &quot;Server-Side, Client-Side, NOSQL, Agile Development, Machine Learning, Elastic Search, AWS, C#, OOP, Object Oriented, Programming, SQL, DB, RDBMS, Relational Database, CSS, Angular, AngularJs, JavaScript, TypeScript, JQuery, HTML, PHP, .NET, MVC.NET, DOT.NET, HADOOP, Java, Apache Hive, XML, JSON, AJAX,MySQL, Visual Studio, Bootstrap, XCode, Android, IOS,&quot;, 
77    &quot;Kotlin, Java, Rx, Dagger, Retrofit, Data Binding, Glide, Picasso, Leak Canary,Git, Flow, MVP, MVVM, Junit, Mockito, Espresso, Repository, Pattern, Singleton Pattern, CI/CD, Python, C/C++, C#, HTML, CSS, JavaScript, React, Spring Boot, Slack, XML, Android Arch Components, Material Design, Timber, ML, Kit,&quot;, 
78    &quot;Android SDK, Java, Kotlin, XML, Firebase, Android Studio, GIMP, Illustrator, PHP, API,&quot;, 
79    &quot;Android Development, Java, Firebase, Kotlin, SQLite, Android Studio, SDK Implementation, Mobile Application, Version Control, JSON, IMA SDK, Google AdSense,  Jira, C#, Swift&quot;, 
80    &quot;Java, Android SDK, Java SE, GWT, AWT, SWT, JSP, JSTL, JSF, Hibernate, Struts, Kotlin, Swift, JavaScript, jQuery, Oracle, MySQL, SQLite, PHP, HTML, CSS, C#,GWT, Angular, Bootstrap, Junit, Selenium, Appium, JavaServer Faces, Zend, Eclipse, XCode, Unity, iOS, Firebase, Open Source, Atlassian, Apache, Microsoft, Adobe,&quot;, 
81    &quot;Android, Kotlin, Java, Dart, MVVM, UAT, CI/CD, UI/UX,&quot;, 
82    &quot;GoF Design Patterns, SOLID, MVVM, MVP, MVC, Android Development, AppoloGraphQL, Dagger2, RxJava, Jetpack Components, Kotlin, iOS, Swift, Autolayout, Python, JavaScript&quot;, 
83    &quot;Git, Youtrack, Trello, Jira, CI/CD, Gitlab, Teamcity, Kotlin, Java, Retrofit, Ktor, Android Architechture Compor Room, SQLDelight, RxJava2, Coroutines/Flow, MVP, MVVM, MVI, Python, Scrum, Waterfall&quot;, 
84    &quot;Java, Kotlin, XML, Android SDK, Retrofit, Okhttp, Dagger 2, Eventbus, Multithreating, Design Patterns, RX, Coroutines, Picasso, Glide, MVM, MVVM, MVP, Clean Architecture, Android Jetpack, Android Architecture Component, Espresso, Junit, Mockito, Cucumber, SQLite, Realm, Room, Firebase, Git&quot;, 
85    &quot;invison, Uxpin, Sketch, Figma, Slack Abstract, Adobe XD, Adobe InDesign, Illustrator, Adobe Photoshop, Adobe Muse, Rhinoceros, Animation Studio, MacOS, Microsoft Office, Material Design, Fluent Design, Swift, React, Angular, HTML, CSS, JS, GitHub&quot;, 
86    &quot;PHP, HTML, CSS, JavaScript, React, Python, CRO,  Adobe XD, Sketch, InVision, Lingo App, TripleTex,&quot;, 
87    &quot;Figma, Sketch, Invision, Adobe XD, Adobe Creative Cloud, Craft Marvel,&quot;, 
88    &quot;Figma, Sketch, Photoshop, Illustrator, Adobe After Effects, Maya, Cinema 4D, JavaScript, HTML, CSS, React, Node, Next.js, TailwindCSS, Firebase, MongoDB,&quot;, 
89    &quot;Java, C#.NET, PHP, Python, JavaScript, HTML, CSS, XML, Datenbanken, SQL, Geodaten, CMS Systeme, Jira, Confluence, Linux, Webserver-Betrieb, Catching, Load Balancing, Monitoring CI Systeme, automatisiertes Testen, Deployment,&quot;, 
90    &quot;Software Engineering, DevOps, System Architecture, Agile Transformation, IT Security, Python, Java, CI, CD, Docker, iOS, C++, C#, Golang, Ruby, Node JS, PostgrSQL, MySQL, RethinkDB, Cassandra, Consul&quot;, 
91    &quot;Cobol, Delta, ISAM, Java, JavaScript, CSS, Eclipse RCP, ANTLR, JPA, Maven, JPA/Hibernate, Lucene, HSQL, Oracle, Tomcat, Jetty, Axis, JBoss, JAX-WS, SOAP, WSDL, HBase, Jenkins, SNS, S3, SASS, Jira, Github, SEO/SM, Gitlab, Kotlin, Kafka,&quot;, 
92    &quot;AWS, Azure, Angular, MongoDB, Node.js, iOS,&quot;, &quot;Java, RIM, COM Interfaces, Edifact, MT940, XSLT, XML, Tomcat, JMS, Arvo Workflowsystem, XSL-FO, Xalan, JSP, Servlets, JavaScript, Struts, EJB, JPA, Trinidad, Drools, XFire, Eclipse, Springframework, Dozer Framework,&quot;, 
93    &quot;Android, Java, Python, Rails, Ruby, SQL, Kotlin, Git, Redmine, MariaDB, Gitlab, Jira, Bitbucket, Mattermost, Docker, Jenkins CI,&quot;, 
94    &quot;Trello, Asana, Microsoft Office, Photoshop, Unity 3D,&quot;, 
95    &quot;Java, CMS, Scrum, C++, SOA, EDA, Cloud,&quot;, &quot;SQL, Adobe, Python, SQL, ABAP, React + TypeScript, Node.js, CMS, REST API, Tensorflow + Pytorch, Flutter, AWS Deployment, SAP, Jira, AutoCAD&quot;, 
96    NA), Job1_latest = c(&quot;Senior Engineer - Machine learning&quot;, 
97    &quot;Senior Machine Learning Engineer&quot;, &quot;Application Developer Associate Manager&quot;, 
98    &quot;Senior Data &amp; ML  Engineer&quot;, &quot;Senior Machine Learning Engineer&quot;, 
99    &quot;Software Developer&quot;, &quot;Machine Learning Engineer&quot;, &quot;Akademischer  Mitarbeiter, Machine  Learning  and Analytics&quot;, 
100    &quot;Senior Backend Developer&quot;, &quot;Senior Web Developer&quot;, &quot;Software Architect / Development lead&quot;, 
101    NA, &quot;Data Analysing (Researcher)&quot;, &quot;Software Engineer&quot;, &quot;Sofware Developer&quot;, 
102    &quot;Senior Associate Experience Technology&quot;, &quot;Senior Software Architect&quot;, 
103    &quot;Senior Software Developer / Tech Lead&quot;, &quot;Fullstack Developer/ ProductOwner&quot;, 
104    &quot;Freelancing Software Developer&quot;, &quot;Senior Software Developer / Teamlead&quot;, 
105    &quot;Fullstack JavaScript Developer&quot;, &quot;Blowoutandgo Application Developer&quot;, 
106    &quot;Software Developer&quot;, &quot;Software Engineer&quot;, &quot;Senior Frontend Engineer and Lead Developer&quot;, 
107    &quot;Javascript Developer&quot;, &quot;Data  Scientist/ Python Developer&quot;, 
108    &quot;Research Assistant&quot;, &quot;Fullstack Engineer&quot;, &quot;Backend Developer&quot;, 
109    &quot;App-Backend Developer&quot;, &quot;Senior Software Developer&quot;, &quot;Android Developer&quot;, 
110    &quot;Android Software Engineer&quot;, &quot;Senior Android Developer&quot;, 
111    &quot;Senior C# Developer&quot;, &quot;Software Developer&quot;, &quot;Applications Developer&quot;, 
112    &quot;Senior Android Developer&quot;, &quot;Android Developer&quot;, &quot;Senior Android Engineer&quot;, 
113    &quot;Mobile Engineer&quot;, &quot;Senior Android Developer&quot;, &quot;Software Engineer&quot;, 
114    &quot;Senior UX/UI Designer&quot;, &quot;User Experience Designer&quot;, &quot;Design Consultant&quot;, 
115    &quot;Frontend Product Designer&quot;, &quot;Team Lead Payment Page and Processing&quot;, 
116    &quot;Head of Engineering&quot;, &quot;Senior Software Engineering Manager&quot;, 
117    &quot;Head of Technology&quot;, &quot;Head of Development&quot;, &quot;Senior Software Developer&quot;, 
118    &quot;Producer&quot;, &quot;Vice President&quot;, &quot;Software Developer&quot;, NA), 
119    Years1 = c(3, 1, 2, 1, 2, 2, 2, 1, 5, 5, 5, NA, NA, 1, 4, 
120    1, 6, 1, 2, 4, 2, 3, 3, 3, 1, 1, 2, 2, 1, 2, 4, 1, 1, 1, 
121    2, NA, 1, 1, 4, 1, 1, 3, 2, 1, 1, 1, 1, 1, 1, 2, 3, 3, 4, 
122    2, 2, 6, 1, 2, NA), Job2 = c(&quot;Data Scientist&quot;, &quot;Machine Learning Engineer&quot;, 
123    &quot;Machine Learning Developer - Associate Manager&quot;, &quot;Senior DWH&amp;BI Engineer&quot;, 
124    &quot;Co-Founder &amp; CTO&quot;, &quot;Software Developer&quot;, &quot;Data Engineer&quot;, 
125    &quot;Application Software Engineer&quot;, &quot;Backend Develope&quot;, &quot;Lead PHP Developer&quot;, 
126    &quot;Lead PHP developer&quot;, NA, &quot;Machine Learning Engineer&quot;, &quot;Software Engineer&quot;, 
127    &quot;Expert Application Development Specialist&quot;, &quot;SDE 3&quot;, &quot;Developer Trainer &amp; Mentor&quot;, 
128    &quot;Senior Software Developer&quot;, &quot;Senior Software Developer&quot;, 
129    &quot;AI Developer&quot;, &quot;Software Developer &amp; Consulatance&quot;, &quot;Web &amp; Communication Consultance&quot;, 
130    &quot;Mobile Application Development&quot;, &quot;Frontend Developer&quot;, &quot;Web Developer&quot;, 
131    &quot;Fullstack Engineer&quot;, &quot;Javascript Developer&quot;, &quot;Junior Research Scientist&quot;, 
132    &quot;Junior Data Analyst&quot;, &quot;Frontend Engineer&quot;, &quot;Senior Software Developer&quot;, 
133    &quot;Fullstack Developer&quot;, &quot;Senior Software Developer&quot;, &quot;Android Developer&quot;, 
134    &quot;Android Software Engineer&quot;, &quot;Mobile Application Developer&quot;, 
135    &quot;Senior Java Developer&quot;, &quot;Android Developer&quot;, &quot;Android Developer&quot;, 
136    &quot;Mobile Application Developer&quot;, &quot;Mobile Developer&quot;, &quot;Senior Android Engineer&quot;, 
137    &quot;Senior Android Developer&quot;, &quot;Senior Android Developer&quot;, &quot;Software Engineer&quot;, 
138    &quot;UI/UX Designer&quot;, &quot;Senior Information Technology Consultant&quot;, 
139    &quot;Global Head of Design&quot;, &quot;Lead Product Desiger&quot;, &quot;Product Manager / Product Analyst&quot;, 
140    &quot;Lead DevOps Engineer&quot;, &quot;Vice President Tech&quot;, &quot;Head of Product&quot;, 
141    &quot;IT Lead&quot;, &quot;Android Consultant&quot;, &quot;Social Game Designer&quot;, 
142    &quot;Head of Enterprise Architecture&quot;, &quot;Team Supervisor&quot;, NA), 
143    Years2 = c(1, 2, 2, 3, 5, 2, 1, 3, 1, 8, 2, NA, 2, 2, 1, 
144    2, 8, 1, 1, 1, 6, 4, 2, NA, 1, 1, 1, 1, 1, 2, 6, 1, 1, 2, 
145    2, 2, 2, 2, 4, 1, 2, 1, 1, 1, 1, 1, 8, 3, 6, 3, 1, 1, 1, 
146    2, 2, 2, 5, 1, NA), Job3 = c(&quot;Senior Research Scientist&quot;, 
147    &quot;Senior Analytics Analyst&quot;, &quot;Senior Developer&quot;, NA, &quot;Graduate Research Assistant&quot;, 
148    &quot;Software Developer&quot;, NA, NA, &quot;Software Developer&quot;, &quot;Senior Web Developer&quot;, 
149    &quot;Lead PHP/SugarCRM developer&quot;, NA, &quot;Data Engineer&quot;, &quot;Software Engineer&quot;, 
150    &quot;Senior Application Development Specialist&quot;, &quot;Manager L1 (UI/ Frontend)&quot;, 
151    &quot;Application Infrastructor Lead&quot;, &quot;Software Developer&quot;, &quot;Software Developer &amp; Consultance&quot;, 
152    &quot;Software Developer&quot;, &quot;Student Assistant&quot;, NA, &quot;HEB Retail Application&quot;, 
153    NA, NA, &quot;Senior Software Engineer&quot;, &quot;Frontend Web Developer&quot;, 
154    &quot;Computational Scientist/ Backend Developer&quot;, NA, &quot;Fullstack Engineer&quot;, 
155    &quot;IT Specialist - Application Developer&quot;, &quot;Insurance Software Programmer&quot;, 
156    &quot;Software Developer&quot;, &quot;Android Developer&quot;, NA, &quot;Software Developer&quot;, 
157    &quot;Senior C# Developer&quot;, &quot;Embedded Software Intern&quot;, &quot;Android Developer&quot;, 
158    &quot;Android Developer&quot;, &quot;Java Developer&quot;, &quot;Senior Android Engineer&quot;, 
159    NA, &quot;Techlead of Mobile Development Group&quot;, &quot;Software Engineer&quot;, 
160    &quot;Product Designer&quot;, &quot;User Experience Designer&quot;, &quot;Chief UX and Product Architect&quot;, 
161    &quot;Product Designer UI/UX &amp; Motion&quot;, &quot;Senior Web Developer&quot;, 
162    &quot;Lead Developer&quot;, &quot;Senior Manager Digital Platform Development&quot;, 
163    &quot;Head of Engineering&quot;, &quot;IT Manager&quot;, &quot;Head of Software Development&quot;, 
164    &quot;QA Tester&quot;, &quot;Head of Enterprise Archticture, Lead of EA &amp; Innovation&quot;, 
165    &quot;Videography Consultant&quot;, NA), Years3 = c(1, 1, 5, NA, 2, 
166    1, NA, NA, 2, 3, 2, NA, 1, 1, NA, 1, 7, 2, 2, 5, 1, NA, 2, 
167    NA, NA, 1, 1, 4, NA, 1, 1, 4, 2, 2, NA, 1, 1, 1, 1, 1, 4, 
168    2, NA, 1, 1, 1, 1, 1, 1, 3, 2, 2, 1, 1, 2, 1, 4, 1, NA), 
169    Job4 = c(&quot;Research Scientist&quot;, &quot;Analytics Analyst&quot;, &quot;Optical Engineer&quot;, 
170    NA, &quot;Graduate Teaching Assistant&quot;, NA, NA, NA, NA, NA, &quot;PHP/ZEND Developer&quot;, 
171    NA, &quot;Software Engineer&quot;, NA, &quot;Senior Application Development Specialist Consultance&quot;, 
172    &quot;Senior Engineer- Technology&quot;, &quot;Fullstack IOS Developer&quot;, 
173    &quot;Software Engineering Manager/ Solution Architect&quot;, &quot;Senior Software Developer&quot;, 
174    &quot;Software Developer&quot;, NA, NA, NA, NA, NA, &quot;Frontend Engineer and Teamlead Frontend&quot;, 
175    &quot;Forensic Principal Expert at Special Technical Department&quot;, 
176    NA, NA, &quot;Fullstack Engineer&quot;, &quot;Java Web Developer&quot;, &quot;Perl &amp; Oracle Programmer&quot;, 
177    &quot;Software Engineering Manager&quot;, NA, NA, NA, &quot;Senior Web Developer&quot;, 
178    NA, NA, &quot;Software Developer&quot;, &quot;Android Developer&quot;, &quot;Senior Android Engineer/Team Lead&quot;, 
179    NA, &quot;Android/iOS App Developer&quot;, &quot;Software Engineer&quot;, &quot;Art Director, Lead UX/UI Designer&quot;, 
180    &quot;Founder &amp; CEO&quot;, &quot;Director, User Experience&quot;, &quot;Senior Product Designer UI/UX &amp; Motion&quot;, 
181    &quot;Senior Consultant/ Senior Software Engineer&quot;, &quot;CTO &amp; Partner&quot;, 
182    &quot;Senior Consutant/ Architect&quot;, NA, &quot;Managing Director IT&quot;, 
183    &quot;Android Developer&quot;, NA, &quot;Enterprise Architect&quot;, &quot;Software Modification Consultant&quot;, 
184    NA), Years4 = c(5, 2, 3, NA, 5, NA, NA, NA, NA, NA, 3, NA, 
185    2, NA, 6, 1, 9, 2, 8, 1, NA, NA, NA, NA, NA, 2, 1, NA, NA, 
186    1, 1, 3, 2, NA, NA, NA, 3, NA, NA, 1, 1, 4, NA, 1, 2, 2, 
187    2, 1, 5, 3, 2, 2, NA, 2, 4, NA, 1, 2, NA), Job5 = c(&quot;PhD fellow&quot;, 
188    &quot;Java developer Intern&quot;, NA, NA, &quot;Senior Software Engineer&quot;, 
189    NA, NA, NA, NA, NA, &quot;PHP System Analytic / Software specialist&quot;, 
190    NA, NA, NA, &quot;Application Developer Consultance&quot;, &quot;Frontend Engineer&quot;, 
191    NA, &quot;Technical Delivery Manager&quot;, &quot;Application Developer&quot;, 
192    &quot;Software Developer&quot;, NA, NA, NA, NA, NA, NA, &quot;Web Designer/ Developer&quot;, 
193    NA, NA, NA, &quot;Java Software Developer&quot;, &quot;Java Junior Programmer&quot;, 
194    &quot;Technical Delivery Manager&quot;, NA, NA, NA, &quot;Senior Mobile Developer&quot;, 
195    NA, NA, &quot;Software Developer Intern&quot;, &quot;Technical Consultant&quot;, 
196    &quot;Software Engineer&quot;, NA, &quot;Fullstack Android Developer&quot;, &quot;Software Engineer&quot;, 
197    &quot;Senior Designer&quot;, &quot;CEO, PR &amp; Marketing&quot;, &quot;Managing Partner/ User Experience&quot;, 
198    &quot;Art Director&quot;, &quot;Software Entwickler&quot;, &quot;Developer &amp; Consultant&quot;, 
199    &quot;Extern Senior Java Developer&quot;, NA, &quot;Vice President Solution Delivery&quot;, 
200    &quot;Development &amp; Sales&quot;, NA, &quot;Senior Architect E-Commerce&quot;, 
201    &quot;IT &amp; Custom Computer Service&quot;, NA), Years5 = c(3, 1, NA, 
202    NA, 2, NA, NA, NA, NA, NA, 1, NA, NA, NA, 1, 1, NA, 2, 2, 
203    2, NA, NA, NA, NA, NA, NA, 7, NA, NA, NA, 1, 1, 5, NA, NA, 
204    NA, 1, NA, NA, 1, 2, 1, NA, 1, 1, 1, 2, 3, 3, 2, 2, 1, NA, 
205    4, 2, NA, 1, 3, NA), Job6 = c(NA, NA, NA, NA, NA, NA, NA, 
206    NA, NA, NA, &quot;Web Developer&quot;, NA, NA, NA, &quot;Software Instrocture&quot;, 
207    &quot;Associate Software Engineer&quot;, NA, &quot;Software Engineer&quot;, &quot;Software Architect&quot;, 
208    NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, &quot;Software Engineer&quot;, 
209    NA, NA, NA, &quot;Senior Web Developer&quot;, NA, NA, NA, &quot;Software Engineer&quot;, 
210    NA, NA, NA, NA, NA, NA, &quot;Regional Head of Experience&quot;, NA, 
211    NA, &quot;Junior IT Security Analyst&quot;, &quot;Feelance Consulant&quot;, NA, 
212    &quot;Senior Software Engineer&quot;, NA, NA, &quot;Team Lead E-Commerce&quot;, 
213    NA, NA), Years6 = c(NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
214    2, NA, NA, NA, 1, 2, NA, 3, 3, NA, NA, NA, NA, NA, NA, NA, 
215    NA, NA, NA, NA, NA, NA, 1, NA, NA, NA, 2, NA, NA, NA, 2, 
216    NA, NA, NA, NA, NA, NA, 1, NA, NA, 1, 2, NA, 1, NA, NA, 4, 
217    NA, NA), Job7 = c(NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
218    NA, NA, NA, NA, &quot;Assistant Network Administrator&quot;, NA, NA, 
219    &quot;Technical Delivery Manager/ Project Manager&quot;, NA, NA, NA, 
220    NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
221    &quot;Senior Mobile Developer&quot;, NA, NA, NA, &quot;Web Developer&quot;, NA, 
222    NA, NA, NA, NA, NA, NA, NA, NA, NA, &quot;Developement Lead&quot;, 
223    NA, &quot;Chief Software Architect&quot;, NA, NA, &quot;Senior Software Developer&quot;, 
224    NA, NA), Years7 = c(NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
225    NA, NA, NA, NA, 1, NA, NA, 3, NA, NA, NA, NA, NA, NA, NA, 
226    NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 1, NA, NA, NA, 
227    3, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 10, NA, 1, NA, 
228    NA, 3, NA, NA), Job8 = c(NA, NA, NA, NA, NA, NA, NA, NA, 
229    NA, NA, NA, NA, NA, NA, &quot;Trainee ES Computer&quot;, NA, NA, NA, 
230    NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
231    NA, NA, NA, &quot;Big-Data Developer&quot;, NA, NA, NA, &quot;Supervisor Support&quot;, 
232    NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, &quot;Product Development&quot;, 
233    NA, NA, NA, NA, NA), Years8 = c(NA, NA, NA, NA, NA, NA, NA, 
234    NA, NA, NA, NA, NA, NA, NA, 1, NA, NA, NA, NA, NA, NA, NA, 
235    NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 1, 
236    NA, NA, NA, 3, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
237    NA, 1, NA, NA, NA, NA, NA), Job9 = c(NA, NA, NA, NA, NA, 
238    NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
239    NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
240    NA, &quot;Fullstack Developer&quot;, NA, NA, NA, NA, NA, NA, NA, NA, 
241    NA, NA, NA, NA, NA, NA, NA, NA, &quot;Software Architecture&quot;, 
242    NA, NA, NA, NA, NA), Years9 = c(NA, NA, NA, NA, NA, NA, NA, 
243    NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
244    NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 3, 
245    NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
246    NA, 6, NA, NA, NA, NA, NA), Job10 = c(NA, NA, NA, NA, NA, 
247    NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
248    NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
249    NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
250    NA, NA, NA, &quot;Senior Software Developer&quot;, NA, NA, NA, NA, 
251    NA), Years10 = c(NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
252    NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
253    NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
254    NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 3, NA, 
255    NA, NA, NA, NA), Job11 = c(NA, NA, NA, NA, NA, NA, NA, NA, 
256    NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
257    NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
258    NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
259    &quot;Software Developer&quot;, NA, NA, NA, NA, NA), Years11 = c(NA, 
260    NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
261    NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
262    NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
263    NA, NA, NA, NA, NA, NA, NA, 4, NA, NA, NA, NA, NA), Job12 = c(NA, 
264    NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
265    NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
266    NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
267    NA, NA, NA, NA, NA, NA, NA, &quot;IT/ Organisation&quot;, NA, NA, NA, 
268    NA, NA), Years12 = c(NA, NA, NA, NA, NA, NA, NA, NA, NA, 
269    NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
270    NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
271    NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 8, 
272    NA, NA, NA, NA, NA)), problems = structure(list(row = c(13L, 
27324L, 36L), col = c(&quot;Years1&quot;, &quot;Years2&quot;, &quot;Years1&quot;), expected = c(&quot;no trailing characters&quot;, 
274&quot;no trailing characters&quot;, &quot;no trailing characters&quot;), actual = c(&quot;0,2&quot;, 
275&quot;0,6&quot;, &quot;0,4&quot;), file = c(&quot;'Recruitee Tech CVs - Tabellenblatt1 (1).csv'&quot;, 
276&quot;'Recruitee Tech CVs - Tabellenblatt1 (1).csv'&quot;, &quot;'Recruitee Tech CVs - Tabellenblatt1 (1).csv'&quot;
277)), row.names = c(NA, -3L), class = c(&quot;tbl_df&quot;, &quot;tbl&quot;, &quot;data.frame&quot;
278)), class = c(&quot;spec_tbl_df&quot;, &quot;tbl_df&quot;, &quot;tbl&quot;, &quot;data.frame&quot;), row.names = c(NA, 
279-59L), spec = structure(list(cols = list(Index = structure(list(), class = c(&quot;collector_double&quot;, 
280&quot;collector&quot;)), FromJob = structure(list(), class = c(&quot;collector_character&quot;, 
281&quot;collector&quot;)), Highest_education_achieved = structure(list(), class = c(&quot;collector_character&quot;, 
282&quot;collector&quot;)), Skills = structure(list(), class = c(&quot;collector_character&quot;, 
283&quot;collector&quot;)), Job1_latest = structure(list(), class = c(&quot;collector_character&quot;, 
284&quot;collector&quot;)), Years1 = structure(list(), class = c(&quot;collector_double&quot;, 
285&quot;collector&quot;)), Job2 = structure(list(), class = c(&quot;collector_character&quot;, 
286&quot;collector&quot;)), Years2 = structure(list(), class = c(&quot;collector_double&quot;, 
287&quot;collector&quot;)), Job3 = structure(list(), class = c(&quot;collector_character&quot;, 
288&quot;collector&quot;)), Years3 = structure(list(), class = c(&quot;collector_double&quot;, 
289&quot;collector&quot;)), Job4 = structure(list(), class = c(&quot;collector_character&quot;, 
290&quot;collector&quot;)), Years4 = structure(list(), class = c(&quot;collector_double&quot;, 
291&quot;collector&quot;)), Job5 = structure(list(), class = c(&quot;collector_character&quot;, 
292&quot;collector&quot;)), Years5 = structure(list(), class = c(&quot;collector_double&quot;, 
293&quot;collector&quot;)), Job6 = structure(list(), class = c(&quot;collector_character&quot;, 
294&quot;collector&quot;)), Years6 = structure(list(), class = c(&quot;collector_double&quot;, 
295&quot;collector&quot;)), Job7 = structure(list(), class = c(&quot;collector_character&quot;, 
296&quot;collector&quot;)), Years7 = structure(list(), class = c(&quot;collector_double&quot;, 
297&quot;collector&quot;)), Job8 = structure(list(), class = c(&quot;collector_character&quot;, 
298&quot;collector&quot;)), Years8 = structure(list(), class = c(&quot;collector_double&quot;, 
299&quot;collector&quot;)), Job9 = structure(list(), class = c(&quot;collector_character&quot;, 
300&quot;collector&quot;)), Years9 = structure(list(), class = c(&quot;collector_double&quot;, 
301&quot;collector&quot;)), Job10 = structure(list(), class = c(&quot;collector_character&quot;, 
302&quot;collector&quot;)), Years10 = structure(list(), class = c(&quot;collector_double&quot;, 
303&quot;collector&quot;)), Job11 = structure(list(), class = c(&quot;collector_character&quot;, 
304&quot;collector&quot;)), Years11 = structure(list(), class = c(&quot;collector_double&quot;, 
305&quot;collector&quot;)), Job12 = structure(list(), class = c(&quot;collector_character&quot;, 
306&quot;collector&quot;)), Years12 = structure(list(), class = c(&quot;collector_double&quot;, 
307&quot;collector&quot;))), default = structure(list(), class = c(&quot;collector_guess&quot;, 
308&quot;collector&quot;)), skip = 1L), class = &quot;col_spec&quot;))
309

ANSWER

Answered 2021-May-11 at 13:56

You can get the value which is next to last non-NA value.

1structure(list(Index = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 
213, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 
329, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 
445, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59), 
5    FromJob = c(&quot;Senior Machine Learning Engineer&quot;, &quot;Senior Machine Learning Engineer&quot;, 
6    &quot;Senior Machine Learning Engineer&quot;, &quot;Senior Machine Learning Engineer&quot;, 
7    &quot;Senior Machine Learning Engineer&quot;, &quot;Python Data Engineer (m/w/d)&quot;, 
8    &quot;Python Data Engineer (m/w/d)&quot;, &quot;Python Data Engineer (m/w/d)&quot;, 
9    &quot;Lead Backend Developer (f/m/d)&quot;, &quot;Lead Backend Developer (f/m/d)&quot;, 
10    &quot;Lead Backend Developer (f/m/d)&quot;, &quot;Lead Backend Developer (f/m/d)&quot;, 
11    &quot;Python Data Engineer (m/w/d)&quot;, &quot;Python Data Engineer (m/w/d)&quot;, 
12    &quot;Lead Developer&quot;, &quot;Lead Developer&quot;, &quot;Lead Developer&quot;, &quot;Lead Developer&quot;, 
13    &quot;Lead Developer&quot;, &quot;Lead Developer&quot;, &quot;Team Lead Software Development&quot;, 
14    &quot;(Senior) Frontend Engineer&quot;, &quot;(Senior) Frontend Engineer&quot;, 
15    &quot;(Senior) Frontend Engineer&quot;, &quot;(Senior) Frontend Engineer&quot;, 
16    &quot;(Senior) Frontend Engineer&quot;, &quot;(Senior) Frontend Engineer&quot;, 
17    &quot;Data Scientist&quot;, &quot;Data Scientist&quot;, &quot;Senior Backend (Java) Engineer&quot;, 
18    &quot;Senior Backend (Java) Engineer&quot;, &quot;Senior Backend (Java) Engineer&quot;, 
19    &quot;Lead Developer&quot;, &quot;Mobile Software Engineer&quot;, &quot;Mobile Software Engineer&quot;, 
20    &quot;Mobile Software Engineer&quot;, &quot;Mobile Software Engineer&quot;, &quot;Mobile Software Engineer&quot;, 
21    &quot;Mobile Software Engineer&quot;, &quot;Mobile Software Engineer&quot;, &quot;Mobile Software Engineer&quot;, 
22    &quot;Mobile Software Engineer&quot;, &quot;Mobile Software Engineer&quot;, &quot;Mobile Software Engineer&quot;, 
23    &quot;Mobile Software Engineer&quot;, &quot;Lead UI/UX Designer&quot;, &quot;Lead UI/UX Designer&quot;, 
24    &quot;Lead UI/UX Designer&quot;, &quot;Lead UI/UX Designer&quot;, &quot;Head of Software Development&quot;, 
25    &quot;Head of Software Development&quot;, &quot;Head of Software Development&quot;, 
26    &quot;Head of Software Development&quot;, &quot;Head of Software Development&quot;, 
27    &quot;Head of Software Development&quot;, &quot;Head of Software Development&quot;, 
28    &quot;Head of Software Development&quot;, &quot;Jnuior Fullstack Developer&quot;, 
29    NA), Highest_education_achieved = c(&quot;PhD&quot;, &quot;MSc Computer Science&quot;, 
30    &quot;MSc&quot;, &quot;MBA&quot;, &quot;MSc&quot;, &quot;MSc&quot;, &quot;MSc&quot;, &quot;MSc Communication and Media Engineering&quot;, 
31    &quot;High School&quot;, &quot;BSc Informatics&quot;, &quot;BSc Software engineering&quot;, 
32    NA, &quot;MSc in Electronic Engineering&quot;, &quot;MSc in Communication and Media Engineering&quot;, 
33    &quot;BSc in Computer Engineering&quot;, &quot;BSc in Technology&quot;, &quot;MSc in Computer Science&quot;, 
34    &quot;BSc in Automatic Control System&quot;, &quot;Dipl. Wirtschaftsinformatik&quot;, 
35    &quot;MCs Computer Science&quot;, &quot;Dipl. Ing. in Software Development - Economics&quot;, 
36    &quot;MSc in Computer Science&quot;, &quot;BSc. in Information Technology&quot;, 
37    &quot;MSc in Big Data and Business Analyst&quot;, &quot;MSc. in Computer Science&quot;, 
38    &quot;Dipl.&quot;, &quot;BSc.&quot;, &quot;MSc. in Scientific Computing and Biomechanics&quot;, 
39    &quot;MSc. in Computational Engineering&quot;, &quot;MSc. in Information Technology&quot;, 
40    &quot;MSc. in Computer Science&quot;, &quot;MSc. in Informatics&quot;, &quot;BSc.&quot;, 
41    &quot;BSc.&quot;, &quot;BSc.&quot;, &quot;BSc.&quot;, &quot;BSc.&quot;, &quot;BSc.&quot;, &quot;BSc.&quot;, &quot;BSc.&quot;, &quot;Highschool&quot;, 
42    &quot;BSc.&quot;, &quot;BSc.&quot;, &quot;Highschool&quot;, &quot;BSc.&quot;, &quot;MCs.&quot;, &quot;BSc.&quot;, &quot;BSc.&quot;, 
43    &quot;BSc.&quot;, &quot;MCs.&quot;, &quot;BSc.&quot;, &quot;Dipl.&quot;, &quot;BSc.&quot;, &quot;BSc.&quot;, &quot;BSc.&quot;, 
44    &quot;BSc.&quot;, &quot;MSc.&quot;, &quot;BSc.&quot;, NA), Skills = c(&quot;Machine Learning, Mathematical Modeling, Scientific Computing, Linux, python, numpy, scipy, scikit-learn, keras, pandas, javascript, react.js, AWS, Lambda, EMR, EC2, S3, Glue, CloudFormation, git,  Image recognition, deep learning, Natural language processing, Big data integration, cloud migration, Azure, Fortran, OpenFOAM, mercurial&quot;, 
45    &quot;Java, AngularJS, frontend, backend, Azure, data collection, modelbuilding, evaluation, deployment, serving and computing online metrics,  Apache Spark, AWS Sagemaker, Airflow, MLflow, MLOps&quot;, 
46    &quot;Biometrics, Machine Learning, Pattern Recognition, AI, scrum, matlab, C++, Azure, logistics&quot;, 
47    &quot;Databricks, Spark, Airflow, AWS Sagemaker, Other AWS Services, Docker, Microstrategy, Presto, Python, PL/SQL, JavaScript, Shell Scripting, BigQuery (Google), Hadoop, Exasol, Kafka&quot;, 
48    &quot;Spark, Tensorflow &amp;TFX, Kubeflow, BigQuery, Apache Beam (Dataflow), Google Cloud Platform&quot;, 
49    &quot;PythonC++, C, OpenCV, OpenCL, MatLab, TensorFlow/PyTorch, Caffe/Keras, Scikit-learn, Pandas/NumPy, Seaborn/Matplotlib, NLTK/spaCy, Computer Vision, Machine Learning, NLP, Linear/LogisticRegression, Naive Bayes/PCA, SVM/K Means, RandomForest, CNN/LSTM/GRU, Reinforcement Learning&quot;, 
50    &quot;Microsoft SQL Server, Hadoop,SQL Server Management Studio, VisualStudio(DataTools), PyCharm, Sublime text 3, SSIS, python, C#, \nC++, Html/Css, Java,T-SQL, git&quot;, 
51    &quot;Keras, TensorFlow, scikit-learn, NLTK, OpenCV, NumPy, pandas,Python, Java, PHP, HTML, CSS, JavaScript, Angular, React, jQuery, Bootstrap, Flask, SQL, MongoDB, Git, Docker&quot;, 
52    &quot;ElasticSearch, OOP, NoSQL, SQL, Docker, Kibana, Git, Unittest, Openshift&quot;, 
53    &quot;PHP, Java Script, CSS, (X)HTML, MySQL., NodeJS&quot;, &quot;JavaScript (Vue.js, React, jQuery), Node.js (Express), PHP (Yii, Laravel, Symfony), JAVA (Spring Boot), .NET C#, SQL(postregsql, mysql), Elastic, MongoDB, HTML + CSS, Sketch, InVision Studio&quot;, 
54    NA, &quot;Python, C++, HTML/CSS, Java, C#, T-SQL, Microsoft SQL Server, Hadoop, Pycharm, Sublimetext 3, SISS, Git,Liquid Planner,&quot;, 
55    &quot;Keras, TensorFlow, scikit-Learn, NLTK, openCV, NumPy, pandas, Python, Java, PHP, HTML, JavaScript,CSS, Angular, React, jQuery, Bootstrap, Flask, SQL, MonoDB, Git, Android, PhoneGap, Docker&quot;, 
56    &quot;Java, PL/SQL, HTML, JavaScript, PHP, Bash, AngularJs, ReactJs, Python, Weblogic, Jboss, Tomcat, Jetty, Apache, IIS, Unix, Windows, Oracle 8i, 9i, 10g, MySql, MariaDB, PostgrwSql, MS Sql Server, GIT, Mercury, Jira&quot;, 
57    &quot;JavaScript, AngularJs, Angular Next, jQuery, RequireJS, React, WebPack, Typescript, Node, PWA, Socket Programming, Kong,&quot;, 
58    &quot;GIT, SME, API's, iOS, UI, Mobile application, SVN, Epic, Apple, SAML,&quot;, 
59    &quot;Kotlin, Java, JavaScript, Typescript, Pytion ML, AI, Spring, NoSQL, SQL, Microservices, AWS, Azure, Angular9, React, Kafka, Jenkins, Cloud, Rancher, K8s, Cloud foundry, MSSQL, Elas, Tensorflow, Boot, Teras, Hibernite, RabbitMQ, JUnit, AWS SQS, Docker, C++, STL, XML, Linux, Bash,&quot;, 
60    &quot;Scrum, Code Reviews, JIRA, Mantis, Kanban, Trello, Java, Kotlin, Typescript, Groovy, JavaScript, Delphi, Openshift, Kubernetes, Docker, Azure, Open Telekom Cloud, CosmosDB, Heroku, REST, SOAP, XMPP, NATS, JMS, ActiveMQ, Gatling, Mocktesting, Mockito, EasyMock, Cucumber, Angular 8, React, GWT, JSF, JSP, Struts, Spring Boot, JEE, Hibernate, JPA, MongoDB, Oracle, Postgres, CosmosDB, MySQL, DB2, SQL-Tuning, Maven, Ant, Gradle, GIT, SVN, CVS, BIRT, JasperReports, MicroStrategy, Maven,&quot;, 
61    &quot;Kotlin, Java 11, Docker, AWS, GCP, Kubernetes,Neo-4j, Solr, Spring-boot, Postgres, Hibernate, Flyway, sendGrit, Gradl, rxJava, Freemaker, Grafana, Prometheus,Oauth 2, Spring-gateway, Microservices, AWS, Amazon EMR, DynamoDB, S3, Hive, hdfs, storm, kafka, reactive programming, spring-cloud, groovy, elasticsearch, hystrix, ribbon, eureka, API, java 8, grunt, bamboo, jenkins, JavaScript, Junit, jbpm, jmx, C++, j2ee, servlet,&quot;, 
62    &quot;Scrum, SAP, NetWeaver 7.40&quot;, &quot;CSS. Html, Bootstrap, Php, MySQL, JavaScript, Wordpress, Typo 3, Google Analytics, Google Adwords, React, GatsbyJS, Nextjs, Flutter, Postgres, AWS, Docker, Google Cloud Platform,&quot;, 
63    &quot;Node JS, JavaScript, ES6, CSS, PHP, XML, JQuery, Lambda, Appsync, React, JS, HTML5, CSS3, Bootstrap, REST web services, Microservices, JSON, Elasticsearch, Java, React JS, AWS Server, MAMP, Maven, Laravel, Codeigniter, MySQL, Dynamo DB, SQLite, Oracle, MS SQL, MAC, UNIX, Windows, Git, AWS-EC2, S3, Cloud Formation, Cloudwatch, SNS, PhpStorm, WebSorm, Visual Studio Code, Eclipse, Netbeans, Android Studio&quot;, 
64    &quot;C, C++, Java, J2EE, Dotnet, Angular, React, JS, JavaScript, Query, CSS, HTML, Microsoft SQL Server, GIT, React JS with Redux, Vue JS, CSS3, Bootstrap, Media query, AEM, Jest test, Python, Tabeleau, AWS, Miro&quot;, 
65    &quot;JavaScript, ReactJs, TypeScript, Python, C++, HTML, ASP, C#&quot;, 
66    &quot;SPA, TypeScript, React Hooks, Jest, Lerna, React Query, Azure DevOps, Storybook, RxJx, Socket.io, OpenAPI, SCSS,&quot;, 
67    &quot;JavaScript, React JS, Flow, Redux, React SSR, urql graphql client, Java 11, HTML5, CSSS3, JavaScript (ES6+), TypeScript, jQuery, AJAX, webpack, NodeJS, PHP, Express, MongoDB, SASS, Heroku, Linux, Hetzner, Git, AngularJS,&quot;, 
68    &quot;Linux, Windows, MS Office, Libre office, Python, SQL, Bash, C/C++, MATLAB, NumPy, SciPy, pandas, SciKit-Learn, statsmodels, Keras, TensorFlow, Flask, Matplotlib, Seaborn, Tableau, ParaView, Tecplot, Inkscape, GIMP, PyCharm, jupyter, Eclipse, Visual Studio, Git, Docker, Poetry, Pytest, Unittest, Pylint, Pre-commit&quot;, 
69    &quot;Python, C/C++, SQL, MySQL, Numpy, Pandas, Scipy, Scikit-Learn, Keras, Tensorflow, Theano, PyTorch, Visual Studio, Pycharm, Jupyter Notebook, Vscode, PowerBi, MS Office, Sourcetree, Jira, Git, Linux, Mac, Windows&quot;, 
70    &quot;NPM, Webpack, Bower, Gruntjs, Gulp, JavaScript, Angular, CSS, Animation, Angular-animation, TypeScript, ReactJS, Node.js, Lombok, Vue.js, Visual Studio, HTML, Maven, Redux, Chart.js, Kotlin,&quot;, 
71    &quot;Java. Web Services, Design Patterns, Agile Methodologies, Spring Hibernate, JSF, JUnit, Maven Eclipse, SQL, XML, Linux, Websphere, Tomcat, jQuery, Ant, JDBC, Subversion, JavaScript, CSS, JPA, Git, Jenkins, REST, services, AJAX, Glassfish, Java Enterprise Edition, Apache, Lucene, Artifactory,&quot;, 
72    &quot;Java, HTML, Perl, Programming, SQL, JavaScript, CSS, Oracle, C++, Linux, CSS, PHP, C#, Ruby, C&quot;, 
73    NA, &quot;Jira, Git, Scrum, Agile, Retrofit, Picasso, Volley, RESTful, HTTP, JSON, Asyns-task, Dagger2, MVVM Architecture, API, SQLite, Pandas, NumPy,&quot;, 
74    &quot;Kotlin, MVVM Archtiecture, Firebase, Google-Services, Git, Retrofit, JSON, Material Design UI, Constrains Layout Animations, Jira, Figma, Zeplin, Agile, Scrum&quot;, 
75    &quot;C++, Java, MVC Design, AdMob, Google Maps API Keys, Retrofit, Gson, SQLite, Picasso, Google Vision, Play Services, SQL, iOS Develpment, JSON, C#, XML, Android&quot;, 
76    &quot;Server-Side, Client-Side, NOSQL, Agile Development, Machine Learning, Elastic Search, AWS, C#, OOP, Object Oriented, Programming, SQL, DB, RDBMS, Relational Database, CSS, Angular, AngularJs, JavaScript, TypeScript, JQuery, HTML, PHP, .NET, MVC.NET, DOT.NET, HADOOP, Java, Apache Hive, XML, JSON, AJAX,MySQL, Visual Studio, Bootstrap, XCode, Android, IOS,&quot;, 
77    &quot;Kotlin, Java, Rx, Dagger, Retrofit, Data Binding, Glide, Picasso, Leak Canary,Git, Flow, MVP, MVVM, Junit, Mockito, Espresso, Repository, Pattern, Singleton Pattern, CI/CD, Python, C/C++, C#, HTML, CSS, JavaScript, React, Spring Boot, Slack, XML, Android Arch Components, Material Design, Timber, ML, Kit,&quot;, 
78    &quot;Android SDK, Java, Kotlin, XML, Firebase, Android Studio, GIMP, Illustrator, PHP, API,&quot;, 
79    &quot;Android Development, Java, Firebase, Kotlin, SQLite, Android Studio, SDK Implementation, Mobile Application, Version Control, JSON, IMA SDK, Google AdSense,  Jira, C#, Swift&quot;, 
80    &quot;Java, Android SDK, Java SE, GWT, AWT, SWT, JSP, JSTL, JSF, Hibernate, Struts, Kotlin, Swift, JavaScript, jQuery, Oracle, MySQL, SQLite, PHP, HTML, CSS, C#,GWT, Angular, Bootstrap, Junit, Selenium, Appium, JavaServer Faces, Zend, Eclipse, XCode, Unity, iOS, Firebase, Open Source, Atlassian, Apache, Microsoft, Adobe,&quot;, 
81    &quot;Android, Kotlin, Java, Dart, MVVM, UAT, CI/CD, UI/UX,&quot;, 
82    &quot;GoF Design Patterns, SOLID, MVVM, MVP, MVC, Android Development, AppoloGraphQL, Dagger2, RxJava, Jetpack Components, Kotlin, iOS, Swift, Autolayout, Python, JavaScript&quot;, 
83    &quot;Git, Youtrack, Trello, Jira, CI/CD, Gitlab, Teamcity, Kotlin, Java, Retrofit, Ktor, Android Architechture Compor Room, SQLDelight, RxJava2, Coroutines/Flow, MVP, MVVM, MVI, Python, Scrum, Waterfall&quot;, 
84    &quot;Java, Kotlin, XML, Android SDK, Retrofit, Okhttp, Dagger 2, Eventbus, Multithreating, Design Patterns, RX, Coroutines, Picasso, Glide, MVM, MVVM, MVP, Clean Architecture, Android Jetpack, Android Architecture Component, Espresso, Junit, Mockito, Cucumber, SQLite, Realm, Room, Firebase, Git&quot;, 
85    &quot;invison, Uxpin, Sketch, Figma, Slack Abstract, Adobe XD, Adobe InDesign, Illustrator, Adobe Photoshop, Adobe Muse, Rhinoceros, Animation Studio, MacOS, Microsoft Office, Material Design, Fluent Design, Swift, React, Angular, HTML, CSS, JS, GitHub&quot;, 
86    &quot;PHP, HTML, CSS, JavaScript, React, Python, CRO,  Adobe XD, Sketch, InVision, Lingo App, TripleTex,&quot;, 
87    &quot;Figma, Sketch, Invision, Adobe XD, Adobe Creative Cloud, Craft Marvel,&quot;, 
88    &quot;Figma, Sketch, Photoshop, Illustrator, Adobe After Effects, Maya, Cinema 4D, JavaScript, HTML, CSS, React, Node, Next.js, TailwindCSS, Firebase, MongoDB,&quot;, 
89    &quot;Java, C#.NET, PHP, Python, JavaScript, HTML, CSS, XML, Datenbanken, SQL, Geodaten, CMS Systeme, Jira, Confluence, Linux, Webserver-Betrieb, Catching, Load Balancing, Monitoring CI Systeme, automatisiertes Testen, Deployment,&quot;, 
90    &quot;Software Engineering, DevOps, System Architecture, Agile Transformation, IT Security, Python, Java, CI, CD, Docker, iOS, C++, C#, Golang, Ruby, Node JS, PostgrSQL, MySQL, RethinkDB, Cassandra, Consul&quot;, 
91    &quot;Cobol, Delta, ISAM, Java, JavaScript, CSS, Eclipse RCP, ANTLR, JPA, Maven, JPA/Hibernate, Lucene, HSQL, Oracle, Tomcat, Jetty, Axis, JBoss, JAX-WS, SOAP, WSDL, HBase, Jenkins, SNS, S3, SASS, Jira, Github, SEO/SM, Gitlab, Kotlin, Kafka,&quot;, 
92    &quot;AWS, Azure, Angular, MongoDB, Node.js, iOS,&quot;, &quot;Java, RIM, COM Interfaces, Edifact, MT940, XSLT, XML, Tomcat, JMS, Arvo Workflowsystem, XSL-FO, Xalan, JSP, Servlets, JavaScript, Struts, EJB, JPA, Trinidad, Drools, XFire, Eclipse, Springframework, Dozer Framework,&quot;, 
93    &quot;Android, Java, Python, Rails, Ruby, SQL, Kotlin, Git, Redmine, MariaDB, Gitlab, Jira, Bitbucket, Mattermost, Docker, Jenkins CI,&quot;, 
94    &quot;Trello, Asana, Microsoft Office, Photoshop, Unity 3D,&quot;, 
95    &quot;Java, CMS, Scrum, C++, SOA, EDA, Cloud,&quot;, &quot;SQL, Adobe, Python, SQL, ABAP, React + TypeScript, Node.js, CMS, REST API, Tensorflow + Pytorch, Flutter, AWS Deployment, SAP, Jira, AutoCAD&quot;, 
96    NA), Job1_latest = c(&quot;Senior Engineer - Machine learning&quot;, 
97    &quot;Senior Machine Learning Engineer&quot;, &quot;Application Developer Associate Manager&quot;, 
98    &quot;Senior Data &amp; ML  Engineer&quot;, &quot;Senior Machine Learning Engineer&quot;, 
99    &quot;Software Developer&quot;, &quot;Machine Learning Engineer&quot;, &quot;Akademischer  Mitarbeiter, Machine  Learning  and Analytics&quot;, 
100    &quot;Senior Backend Developer&quot;, &quot;Senior Web Developer&quot;, &quot;Software Architect / Development lead&quot;, 
101    NA, &quot;Data Analysing (Researcher)&quot;, &quot;Software Engineer&quot;, &quot;Sofware Developer&quot;, 
102    &quot;Senior Associate Experience Technology&quot;, &quot;Senior Software Architect&quot;, 
103    &quot;Senior Software Developer / Tech Lead&quot;, &quot;Fullstack Developer/ ProductOwner&quot;, 
104    &quot;Freelancing Software Developer&quot;, &quot;Senior Software Developer / Teamlead&quot;, 
105    &quot;Fullstack JavaScript Developer&quot;, &quot;Blowoutandgo Application Developer&quot;, 
106    &quot;Software Developer&quot;, &quot;Software Engineer&quot;, &quot;Senior Frontend Engineer and Lead Developer&quot;, 
107    &quot;Javascript Developer&quot;, &quot;Data  Scientist/ Python Developer&quot;, 
108    &quot;Research Assistant&quot;, &quot;Fullstack Engineer&quot;, &quot;Backend Developer&quot;, 
109    &quot;App-Backend Developer&quot;, &quot;Senior Software Developer&quot;, &quot;Android Developer&quot;, 
110    &quot;Android Software Engineer&quot;, &quot;Senior Android Developer&quot;, 
111    &quot;Senior C# Developer&quot;, &quot;Software Developer&quot;, &quot;Applications Developer&quot;, 
112    &quot;Senior Android Developer&quot;, &quot;Android Developer&quot;, &quot;Senior Android Engineer&quot;, 
113    &quot;Mobile Engineer&quot;, &quot;Senior Android Developer&quot;, &quot;Software Engineer&quot;, 
114    &quot;Senior UX/UI Designer&quot;, &quot;User Experience Designer&quot;, &quot;Design Consultant&quot;, 
115    &quot;Frontend Product Designer&quot;, &quot;Team Lead Payment Page and Processing&quot;, 
116    &quot;Head of Engineering&quot;, &quot;Senior Software Engineering Manager&quot;, 
117    &quot;Head of Technology&quot;, &quot;Head of Development&quot;, &quot;Senior Software Developer&quot;, 
118    &quot;Producer&quot;, &quot;Vice President&quot;, &quot;Software Developer&quot;, NA), 
119    Years1 = c(3, 1, 2, 1, 2, 2, 2, 1, 5, 5, 5, NA, NA, 1, 4, 
120    1, 6, 1, 2, 4, 2, 3, 3, 3, 1, 1, 2, 2, 1, 2, 4, 1, 1, 1, 
121    2, NA, 1, 1, 4, 1, 1, 3, 2, 1, 1, 1, 1, 1, 1, 2, 3, 3, 4, 
122    2, 2, 6, 1, 2, NA), Job2 = c(&quot;Data Scientist&quot;, &quot;Machine Learning Engineer&quot;, 
123    &quot;Machine Learning Developer - Associate Manager&quot;, &quot;Senior DWH&amp;BI Engineer&quot;, 
124    &quot;Co-Founder &amp; CTO&quot;, &quot;Software Developer&quot;, &quot;Data Engineer&quot;, 
125    &quot;Application Software Engineer&quot;, &quot;Backend Develope&quot;, &quot;Lead PHP Developer&quot;, 
126    &quot;Lead PHP developer&quot;, NA, &quot;Machine Learning Engineer&quot;, &quot;Software Engineer&quot;, 
127    &quot;Expert Application Development Specialist&quot;, &quot;SDE 3&quot;, &quot;Developer Trainer &amp; Mentor&quot;, 
128    &quot;Senior Software Developer&quot;, &quot;Senior Software Developer&quot;, 
129    &quot;AI Developer&quot;, &quot;Software Developer &amp; Consulatance&quot;, &quot;Web &amp; Communication Consultance&quot;, 
130    &quot;Mobile Application Development&quot;, &quot;Frontend Developer&quot;, &quot;Web Developer&quot;, 
131    &quot;Fullstack Engineer&quot;, &quot;Javascript Developer&quot;, &quot;Junior Research Scientist&quot;, 
132    &quot;Junior Data Analyst&quot;, &quot;Frontend Engineer&quot;, &quot;Senior Software Developer&quot;, 
133    &quot;Fullstack Developer&quot;, &quot;Senior Software Developer&quot;, &quot;Android Developer&quot;, 
134    &quot;Android Software Engineer&quot;, &quot;Mobile Application Developer&quot;, 
135    &quot;Senior Java Developer&quot;, &quot;Android Developer&quot;, &quot;Android Developer&quot;, 
136    &quot;Mobile Application Developer&quot;, &quot;Mobile Developer&quot;, &quot;Senior Android Engineer&quot;, 
137    &quot;Senior Android Developer&quot;, &quot;Senior Android Developer&quot;, &quot;Software Engineer&quot;, 
138    &quot;UI/UX Designer&quot;, &quot;Senior Information Technology Consultant&quot;, 
139    &quot;Global Head of Design&quot;, &quot;Lead Product Desiger&quot;, &quot;Product Manager / Product Analyst&quot;, 
140    &quot;Lead DevOps Engineer&quot;, &quot;Vice President Tech&quot;, &quot;Head of Product&quot;, 
141    &quot;IT Lead&quot;, &quot;Android Consultant&quot;, &quot;Social Game Designer&quot;, 
142    &quot;Head of Enterprise Architecture&quot;, &quot;Team Supervisor&quot;, NA), 
143    Years2 = c(1, 2, 2, 3, 5, 2, 1, 3, 1, 8, 2, NA, 2, 2, 1, 
144    2, 8, 1, 1, 1, 6, 4, 2, NA, 1, 1, 1, 1, 1, 2, 6, 1, 1, 2, 
145    2, 2, 2, 2, 4, 1, 2, 1, 1, 1, 1, 1, 8, 3, 6, 3, 1, 1, 1, 
146    2, 2, 2, 5, 1, NA), Job3 = c(&quot;Senior Research Scientist&quot;, 
147    &quot;Senior Analytics Analyst&quot;, &quot;Senior Developer&quot;, NA, &quot;Graduate Research Assistant&quot;, 
148    &quot;Software Developer&quot;, NA, NA, &quot;Software Developer&quot;, &quot;Senior Web Developer&quot;, 
149    &quot;Lead PHP/SugarCRM developer&quot;, NA, &quot;Data Engineer&quot;, &quot;Software Engineer&quot;, 
150    &quot;Senior Application Development Specialist&quot;, &quot;Manager L1 (UI/ Frontend)&quot;, 
151    &quot;Application Infrastructor Lead&quot;, &quot;Software Developer&quot;, &quot;Software Developer &amp; Consultance&quot;, 
152    &quot;Software Developer&quot;, &quot;Student Assistant&quot;, NA, &quot;HEB Retail Application&quot;, 
153    NA, NA, &quot;Senior Software Engineer&quot;, &quot;Frontend Web Developer&quot;, 
154    &quot;Computational Scientist/ Backend Developer&quot;, NA, &quot;Fullstack Engineer&quot;, 
155    &quot;IT Specialist - Application Developer&quot;, &quot;Insurance Software Programmer&quot;, 
156    &quot;Software Developer&quot;, &quot;Android Developer&quot;, NA, &quot;Software Developer&quot;, 
157    &quot;Senior C# Developer&quot;, &quot;Embedded Software Intern&quot;, &quot;Android Developer&quot;, 
158    &quot;Android Developer&quot;, &quot;Java Developer&quot;, &quot;Senior Android Engineer&quot;, 
159    NA, &quot;Techlead of Mobile Development Group&quot;, &quot;Software Engineer&quot;, 
160    &quot;Product Designer&quot;, &quot;User Experience Designer&quot;, &quot;Chief UX and Product Architect&quot;, 
161    &quot;Product Designer UI/UX &amp; Motion&quot;, &quot;Senior Web Developer&quot;, 
162    &quot;Lead Developer&quot;, &quot;Senior Manager Digital Platform Development&quot;, 
163    &quot;Head of Engineering&quot;, &quot;IT Manager&quot;, &quot;Head of Software Development&quot;, 
164    &quot;QA Tester&quot;, &quot;Head of Enterprise Archticture, Lead of EA &amp; Innovation&quot;, 
165    &quot;Videography Consultant&quot;, NA), Years3 = c(1, 1, 5, NA, 2, 
166    1, NA, NA, 2, 3, 2, NA, 1, 1, NA, 1, 7, 2, 2, 5, 1, NA, 2, 
167    NA, NA, 1, 1, 4, NA, 1, 1, 4, 2, 2, NA, 1, 1, 1, 1, 1, 4, 
168    2, NA, 1, 1, 1, 1, 1, 1, 3, 2, 2, 1, 1, 2, 1, 4, 1, NA), 
169    Job4 = c(&quot;Research Scientist&quot;, &quot;Analytics Analyst&quot;, &quot;Optical Engineer&quot;, 
170    NA, &quot;Graduate Teaching Assistant&quot;, NA, NA, NA, NA, NA, &quot;PHP/ZEND Developer&quot;, 
171    NA, &quot;Software Engineer&quot;, NA, &quot;Senior Application Development Specialist Consultance&quot;, 
172    &quot;Senior Engineer- Technology&quot;, &quot;Fullstack IOS Developer&quot;, 
173    &quot;Software Engineering Manager/ Solution Architect&quot;, &quot;Senior Software Developer&quot;, 
174    &quot;Software Developer&quot;, NA, NA, NA, NA, NA, &quot;Frontend Engineer and Teamlead Frontend&quot;, 
175    &quot;Forensic Principal Expert at Special Technical Department&quot;, 
176    NA, NA, &quot;Fullstack Engineer&quot;, &quot;Java Web Developer&quot;, &quot;Perl &amp; Oracle Programmer&quot;, 
177    &quot;Software Engineering Manager&quot;, NA, NA, NA, &quot;Senior Web Developer&quot;, 
178    NA, NA, &quot;Software Developer&quot;, &quot;Android Developer&quot;, &quot;Senior Android Engineer/Team Lead&quot;, 
179    NA, &quot;Android/iOS App Developer&quot;, &quot;Software Engineer&quot;, &quot;Art Director, Lead UX/UI Designer&quot;, 
180    &quot;Founder &amp; CEO&quot;, &quot;Director, User Experience&quot;, &quot;Senior Product Designer UI/UX &amp; Motion&quot;, 
181    &quot;Senior Consultant/ Senior Software Engineer&quot;, &quot;CTO &amp; Partner&quot;, 
182    &quot;Senior Consutant/ Architect&quot;, NA, &quot;Managing Director IT&quot;, 
183    &quot;Android Developer&quot;, NA, &quot;Enterprise Architect&quot;, &quot;Software Modification Consultant&quot;, 
184    NA), Years4 = c(5, 2, 3, NA, 5, NA, NA, NA, NA, NA, 3, NA, 
185    2, NA, 6, 1, 9, 2, 8, 1, NA, NA, NA, NA, NA, 2, 1, NA, NA, 
186    1, 1, 3, 2, NA, NA, NA, 3, NA, NA, 1, 1, 4, NA, 1, 2, 2, 
187    2, 1, 5, 3, 2, 2, NA, 2, 4, NA, 1, 2, NA), Job5 = c(&quot;PhD fellow&quot;, 
188    &quot;Java developer Intern&quot;, NA, NA, &quot;Senior Software Engineer&quot;, 
189    NA, NA, NA, NA, NA, &quot;PHP System Analytic / Software specialist&quot;, 
190    NA, NA, NA, &quot;Application Developer Consultance&quot;, &quot;Frontend Engineer&quot;, 
191    NA, &quot;Technical Delivery Manager&quot;, &quot;Application Developer&quot;, 
192    &quot;Software Developer&quot;, NA, NA, NA, NA, NA, NA, &quot;Web Designer/ Developer&quot;, 
193    NA, NA, NA, &quot;Java Software Developer&quot;, &quot;Java Junior Programmer&quot;, 
194    &quot;Technical Delivery Manager&quot;, NA, NA, NA, &quot;Senior Mobile Developer&quot;, 
195    NA, NA, &quot;Software Developer Intern&quot;, &quot;Technical Consultant&quot;, 
196    &quot;Software Engineer&quot;, NA, &quot;Fullstack Android Developer&quot;, &quot;Software Engineer&quot;, 
197    &quot;Senior Designer&quot;, &quot;CEO, PR &amp; Marketing&quot;, &quot;Managing Partner/ User Experience&quot;, 
198    &quot;Art Director&quot;, &quot;Software Entwickler&quot;, &quot;Developer &amp; Consultant&quot;, 
199    &quot;Extern Senior Java Developer&quot;, NA, &quot;Vice President Solution Delivery&quot;, 
200    &quot;Development &amp; Sales&quot;, NA, &quot;Senior Architect E-Commerce&quot;, 
201    &quot;IT &amp; Custom Computer Service&quot;, NA), Years5 = c(3, 1, NA, 
202    NA, 2, NA, NA, NA, NA, NA, 1, NA, NA, NA, 1, 1, NA, 2, 2, 
203    2, NA, NA, NA, NA, NA, NA, 7, NA, NA, NA, 1, 1, 5, NA, NA, 
204    NA, 1, NA, NA, 1, 2, 1, NA, 1, 1, 1, 2, 3, 3, 2, 2, 1, NA, 
205    4, 2, NA, 1, 3, NA), Job6 = c(NA, NA, NA, NA, NA, NA, NA, 
206    NA, NA, NA, &quot;Web Developer&quot;, NA, NA, NA, &quot;Software Instrocture&quot;, 
207    &quot;Associate Software Engineer&quot;, NA, &quot;Software Engineer&quot;, &quot;Software Architect&quot;, 
208    NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, &quot;Software Engineer&quot;, 
209    NA, NA, NA, &quot;Senior Web Developer&quot;, NA, NA, NA, &quot;Software Engineer&quot;, 
210    NA, NA, NA, NA, NA, NA, &quot;Regional Head of Experience&quot;, NA, 
211    NA, &quot;Junior IT Security Analyst&quot;, &quot;Feelance Consulant&quot;, NA, 
212    &quot;Senior Software Engineer&quot;, NA, NA, &quot;Team Lead E-Commerce&quot;, 
213    NA, NA), Years6 = c(NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
214    2, NA, NA, NA, 1, 2, NA, 3, 3, NA, NA, NA, NA, NA, NA, NA, 
215    NA, NA, NA, NA, NA, NA, 1, NA, NA, NA, 2, NA, NA, NA, 2, 
216    NA, NA, NA, NA, NA, NA, 1, NA, NA, 1, 2, NA, 1, NA, NA, 4, 
217    NA, NA), Job7 = c(NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
218    NA, NA, NA, NA, &quot;Assistant Network Administrator&quot;, NA, NA, 
219    &quot;Technical Delivery Manager/ Project Manager&quot;, NA, NA, NA, 
220    NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
221    &quot;Senior Mobile Developer&quot;, NA, NA, NA, &quot;Web Developer&quot;, NA, 
222    NA, NA, NA, NA, NA, NA, NA, NA, NA, &quot;Developement Lead&quot;, 
223    NA, &quot;Chief Software Architect&quot;, NA, NA, &quot;Senior Software Developer&quot;, 
224    NA, NA), Years7 = c(NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
225    NA, NA, NA, NA, 1, NA, NA, 3, NA, NA, NA, NA, NA, NA, NA, 
226    NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 1, NA, NA, NA, 
227    3, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 10, NA, 1, NA, 
228    NA, 3, NA, NA), Job8 = c(NA, NA, NA, NA, NA, NA, NA, NA, 
229    NA, NA, NA, NA, NA, NA, &quot;Trainee ES Computer&quot;, NA, NA, NA, 
230    NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
231    NA, NA, NA, &quot;Big-Data Developer&quot;, NA, NA, NA, &quot;Supervisor Support&quot;, 
232    NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, &quot;Product Development&quot;, 
233    NA, NA, NA, NA, NA), Years8 = c(NA, NA, NA, NA, NA, NA, NA, 
234    NA, NA, NA, NA, NA, NA, NA, 1, NA, NA, NA, NA, NA, NA, NA, 
235    NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 1, 
236    NA, NA, NA, 3, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
237    NA, 1, NA, NA, NA, NA, NA), Job9 = c(NA, NA, NA, NA, NA, 
238    NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
239    NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
240    NA, &quot;Fullstack Developer&quot;, NA, NA, NA, NA, NA, NA, NA, NA, 
241    NA, NA, NA, NA, NA, NA, NA, NA, &quot;Software Architecture&quot;, 
242    NA, NA, NA, NA, NA), Years9 = c(NA, NA, NA, NA, NA, NA, NA, 
243    NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
244    NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 3, 
245    NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
246    NA, 6, NA, NA, NA, NA, NA), Job10 = c(NA, NA, NA, NA, NA, 
247    NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
248    NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
249    NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
250    NA, NA, NA, &quot;Senior Software Developer&quot;, NA, NA, NA, NA, 
251    NA), Years10 = c(NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
252    NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
253    NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
254    NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 3, NA, 
255    NA, NA, NA, NA), Job11 = c(NA, NA, NA, NA, NA, NA, NA, NA, 
256    NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
257    NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
258    NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
259    &quot;Software Developer&quot;, NA, NA, NA, NA, NA), Years11 = c(NA, 
260    NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
261    NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
262    NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
263    NA, NA, NA, NA, NA, NA, NA, 4, NA, NA, NA, NA, NA), Job12 = c(NA, 
264    NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
265    NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
266    NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
267    NA, NA, NA, NA, NA, NA, NA, &quot;IT/ Organisation&quot;, NA, NA, NA, 
268    NA, NA), Years12 = c(NA, NA, NA, NA, NA, NA, NA, NA, NA, 
269    NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
270    NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
271    NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 8, 
272    NA, NA, NA, NA, NA)), problems = structure(list(row = c(13L, 
27324L, 36L), col = c(&quot;Years1&quot;, &quot;Years2&quot;, &quot;Years1&quot;), expected = c(&quot;no trailing characters&quot;, 
274&quot;no trailing characters&quot;, &quot;no trailing characters&quot;), actual = c(&quot;0,2&quot;, 
275&quot;0,6&quot;, &quot;0,4&quot;), file = c(&quot;'Recruitee Tech CVs - Tabellenblatt1 (1).csv'&quot;, 
276&quot;'Recruitee Tech CVs - Tabellenblatt1 (1).csv'&quot;, &quot;'Recruitee Tech CVs - Tabellenblatt1 (1).csv'&quot;
277)), row.names = c(NA, -3L), class = c(&quot;tbl_df&quot;, &quot;tbl&quot;, &quot;data.frame&quot;
278)), class = c(&quot;spec_tbl_df&quot;, &quot;tbl_df&quot;, &quot;tbl&quot;, &quot;data.frame&quot;), row.names = c(NA, 
279-59L), spec = structure(list(cols = list(Index = structure(list(), class = c(&quot;collector_double&quot;, 
280&quot;collector&quot;)), FromJob = structure(list(), class = c(&quot;collector_character&quot;, 
281&quot;collector&quot;)), Highest_education_achieved = structure(list(), class = c(&quot;collector_character&quot;, 
282&quot;collector&quot;)), Skills = structure(list(), class = c(&quot;collector_character&quot;, 
283&quot;collector&quot;)), Job1_latest = structure(list(), class = c(&quot;collector_character&quot;, 
284&quot;collector&quot;)), Years1 = structure(list(), class = c(&quot;collector_double&quot;, 
285&quot;collector&quot;)), Job2 = structure(list(), class = c(&quot;collector_character&quot;, 
286&quot;collector&quot;)), Years2 = structure(list(), class = c(&quot;collector_double&quot;, 
287&quot;collector&quot;)), Job3 = structure(list(), class = c(&quot;collector_character&quot;, 
288&quot;collector&quot;)), Years3 = structure(list(), class = c(&quot;collector_double&quot;, 
289&quot;collector&quot;)), Job4 = structure(list(), class = c(&quot;collector_character&quot;, 
290&quot;collector&quot;)), Years4 = structure(list(), class = c(&quot;collector_double&quot;, 
291&quot;collector&quot;)), Job5 = structure(list(), class = c(&quot;collector_character&quot;, 
292&quot;collector&quot;)), Years5 = structure(list(), class = c(&quot;collector_double&quot;, 
293&quot;collector&quot;)), Job6 = structure(list(), class = c(&quot;collector_character&quot;, 
294&quot;collector&quot;)), Years6 = structure(list(), class = c(&quot;collector_double&quot;, 
295&quot;collector&quot;)), Job7 = structure(list(), class = c(&quot;collector_character&quot;, 
296&quot;collector&quot;)), Years7 = structure(list(), class = c(&quot;collector_double&quot;, 
297&quot;collector&quot;)), Job8 = structure(list(), class = c(&quot;collector_character&quot;, 
298&quot;collector&quot;)), Years8 = structure(list(), class = c(&quot;collector_double&quot;, 
299&quot;collector&quot;)), Job9 = structure(list(), class = c(&quot;collector_character&quot;, 
300&quot;collector&quot;)), Years9 = structure(list(), class = c(&quot;collector_double&quot;, 
301&quot;collector&quot;)), Job10 = structure(list(), class = c(&quot;collector_character&quot;, 
302&quot;collector&quot;)), Years10 = structure(list(), class = c(&quot;collector_double&quot;, 
303&quot;collector&quot;)), Job11 = structure(list(), class = c(&quot;collector_character&quot;, 
304&quot;collector&quot;)), Years11 = structure(list(), class = c(&quot;collector_double&quot;, 
305&quot;collector&quot;)), Job12 = structure(list(), class = c(&quot;collector_character&quot;, 
306&quot;collector&quot;)), Years12 = structure(list(), class = c(&quot;collector_double&quot;, 
307&quot;collector&quot;))), default = structure(list(), class = c(&quot;collector_guess&quot;, 
308&quot;collector&quot;)), skip = 1L), class = &quot;col_spec&quot;))
309first_job &lt;- function(x)   {x1 &lt;- x[!is.na(x)];x1[length(x1) - 1][1]}
310apply(data[-(1:4)], 1, first_job)
311
312#[1] &quot;PhD fellow&quot;               &quot;Java developer Intern&quot;    &quot;Optical Engineer&quot; 
313#[4] &quot;Senior DWH&amp;BI Engineer&quot;   &quot;Senior Software Engineer&quot; &quot;Software Developer&quot;
314

Source https://stackoverflow.com/questions/67486393

QUESTION

Cannot create an instance of ViewModel Class

Asked 2021-May-09 at 07:58

When I try to run my app, it crashes with this logcat error. This problem is very similar to this and this post but all mentioned solutions didn't work for me.

When I searched for this error, I found out that it's usually because of the viewmodelproviders being outdated and people recommending to use the new ViewModelProvider with Factory class but even that didn't work out for me.

java.lang.RuntimeException: Cannot create an instance of class com.emirhalici.notetakingappnvvmexample.NoteViewModel

I don't see where there could be an issue, if I have a tiny syntax error somewhere or something else. It is driving me crazy as I'm a beginner and trying to learn Android Architecture Components. I was following a youtube playlist linked here and his code worked flawlessly when he ran it. Please take a look at it before flagging it as a duplicate. I'm really out of my depth here. Thanks in advance.

logcat error

1    Process: com.emirhalici.notetakingappnvvmexample, PID: 17577
2java.lang.RuntimeException: Unable to start activity ComponentInfo{com.emirhalici.notetakingappnvvmexample/com.emirhalici.notetakingappnvvmexample.MainActivity}: java.lang.RuntimeException: Cannot create an instance of class com.emirhalici.notetakingappnvvmexample.NoteViewModel
3    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3449)
4    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601)
5    at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
6    at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
7    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
8    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066)
9    at android.os.Handler.dispatchMessage(Handler.java:106)
10    at android.os.Looper.loop(Looper.java:223)
11    at android.app.ActivityThread.main(ActivityThread.java:7656)
12    at java.lang.reflect.Method.invoke(Native Method)
13    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
14    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
15 Caused by: java.lang.RuntimeException: Cannot create an instance of class com.emirhalici.notetakingappnvvmexample.NoteViewModel
16    at androidx.lifecycle.ViewModelProvider$AndroidViewModelFactory.create(ViewModelProvider.java:275)
17    at androidx.lifecycle.ViewModelProvider.get(ViewModelProvider.java:187)
18    at androidx.lifecycle.ViewModelProvider.get(ViewModelProvider.java:150)
19    at com.emirhalici.notetakingappnvvmexample.MainActivity.onCreate(MainActivity.java:26)
20    at android.app.Activity.performCreate(Activity.java:8000)
21    at android.app.Activity.performCreate(Activity.java:7984)
22    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1309)
23    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3422)
24    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601) 
25    at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85) 
26    at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) 
27    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) 
28    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066) 
29    at android.os.Handler.dispatchMessage(Handler.java:106) 
30    at android.os.Looper.loop(Looper.java:223) 
31    at android.app.ActivityThread.main(ActivityThread.java:7656) 
32    at java.lang.reflect.Method.invoke(Native Method) 
33    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592) 
34    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947) 
35 Caused by: java.lang.reflect.InvocationTargetException
36    at java.lang.reflect.Constructor.newInstance0(Native Method)
37    at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
38    at androidx.lifecycle.ViewModelProvider$AndroidViewModelFactory.create(ViewModelProvider.java:267)
39    at androidx.lifecycle.ViewModelProvider.get(ViewModelProvider.java:187) 
40    at androidx.lifecycle.ViewModelProvider.get(ViewModelProvider.java:150) 
41    at com.emirhalici.notetakingappnvvmexample.MainActivity.onCreate(MainActivity.java:26) 
42    at android.app.Activity.performCreate(Activity.java:8000) 
43    at android.app.Activity.performCreate(Activity.java:7984) 
44    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1309) 
45    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3422) 
46    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601) 
47    at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85) 
48    at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) 
49    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) 
50    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066) 
51    at android.os.Handler.dispatchMessage(Handler.java:106) 
52    at android.os.Looper.loop(Looper.java:223) 
53    at android.app.ActivityThread.main(ActivityThread.java:7656) 
54    at java.lang.reflect.Method.invoke(Native Method) 
55    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592) 
56    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947) 
57 Caused by: java.lang.RuntimeException: cannot find implementation for com.emirhalici.notetakingappnvvmexample.NoteDatabase. NoteDatabase_Impl does not exist
58    at androidx.room.Room.getGeneratedImplementation(Room.java:97)
59    at androidx.room.RoomDatabase$Builder.build(RoomDatabase.java:1358)
60    at com.emirhalici.notetakingappnvvmexample.NoteDatabase.getInstance(NoteDatabase.java:25)
61    at com.emirhalici.notetakingappnvvmexample.NoteRepository.&lt;init&gt;(NoteRepository.java:15)
62    at com.emirhalici.notetakingappnvvmexample.NoteViewModel.&lt;init&gt;(NoteViewModel.java:19)
63    at java.lang.reflect.Constructor.newInstance0(Native Method) 
64    at java.lang.reflect.Constructor.newInstance(Constructor.java:343) 
65    at androidx.lifecycle.ViewModelProvider$AndroidViewModelFactory.create(ViewModelProvider.java:267) 
66    at androidx.lifecycle.ViewModelProvider.get(ViewModelProvider.java:187) 
67    at androidx.lifecycle.ViewModelProvider.get(ViewModelProvider.java:150) 
68    at com.emirhalici.notetakingappnvvmexample.MainActivity.onCreate(MainActivity.java:26) 
69    at android.app.Activity.performCreate(Activity.java:8000) 
70    at android.app.Activity.performCreate(Activity.java:7984) 
71    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1309) 
72    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3422) 
73    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601) 
74    at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85) 
75    at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) 
76    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) 
77    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066) 
78    at android.os.Handler.dispatchMessage(Handler.java:106) 
79    at android.os.Looper.loop(Looper.java:223) 
80    at android.app.ActivityThread.main(ActivityThread.java:7656) 
81    at java.lang.reflect.Method.invoke(Native Method) 
82    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592) 
83    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947) 
84

MainActivity.java

1    Process: com.emirhalici.notetakingappnvvmexample, PID: 17577
2java.lang.RuntimeException: Unable to start activity ComponentInfo{com.emirhalici.notetakingappnvvmexample/com.emirhalici.notetakingappnvvmexample.MainActivity}: java.lang.RuntimeException: Cannot create an instance of class com.emirhalici.notetakingappnvvmexample.NoteViewModel
3    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3449)
4    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601)
5    at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
6    at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
7    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
8    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066)
9    at android.os.Handler.dispatchMessage(Handler.java:106)
10    at android.os.Looper.loop(Looper.java:223)
11    at android.app.ActivityThread.main(ActivityThread.java:7656)
12    at java.lang.reflect.Method.invoke(Native Method)
13    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
14    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
15 Caused by: java.lang.RuntimeException: Cannot create an instance of class com.emirhalici.notetakingappnvvmexample.NoteViewModel
16    at androidx.lifecycle.ViewModelProvider$AndroidViewModelFactory.create(ViewModelProvider.java:275)
17    at androidx.lifecycle.ViewModelProvider.get(ViewModelProvider.java:187)
18    at androidx.lifecycle.ViewModelProvider.get(ViewModelProvider.java:150)
19    at com.emirhalici.notetakingappnvvmexample.MainActivity.onCreate(MainActivity.java:26)
20    at android.app.Activity.performCreate(Activity.java:8000)
21    at android.app.Activity.performCreate(Activity.java:7984)
22    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1309)
23    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3422)
24    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601) 
25    at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85) 
26    at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) 
27    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) 
28    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066) 
29    at android.os.Handler.dispatchMessage(Handler.java:106) 
30    at android.os.Looper.loop(Looper.java:223) 
31    at android.app.ActivityThread.main(ActivityThread.java:7656) 
32    at java.lang.reflect.Method.invoke(Native Method) 
33    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592) 
34    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947) 
35 Caused by: java.lang.reflect.InvocationTargetException
36    at java.lang.reflect.Constructor.newInstance0(Native Method)
37    at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
38    at androidx.lifecycle.ViewModelProvider$AndroidViewModelFactory.create(ViewModelProvider.java:267)
39    at androidx.lifecycle.ViewModelProvider.get(ViewModelProvider.java:187) 
40    at androidx.lifecycle.ViewModelProvider.get(ViewModelProvider.java:150) 
41    at com.emirhalici.notetakingappnvvmexample.MainActivity.onCreate(MainActivity.java:26) 
42    at android.app.Activity.performCreate(Activity.java:8000) 
43    at android.app.Activity.performCreate(Activity.java:7984) 
44    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1309) 
45    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3422) 
46    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601) 
47    at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85) 
48    at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) 
49    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) 
50    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066) 
51    at android.os.Handler.dispatchMessage(Handler.java:106) 
52    at android.os.Looper.loop(Looper.java:223) 
53    at android.app.ActivityThread.main(ActivityThread.java:7656) 
54    at java.lang.reflect.Method.invoke(Native Method) 
55    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592) 
56    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947) 
57 Caused by: java.lang.RuntimeException: cannot find implementation for com.emirhalici.notetakingappnvvmexample.NoteDatabase. NoteDatabase_Impl does not exist
58    at androidx.room.Room.getGeneratedImplementation(Room.java:97)
59    at androidx.room.RoomDatabase$Builder.build(RoomDatabase.java:1358)
60    at com.emirhalici.notetakingappnvvmexample.NoteDatabase.getInstance(NoteDatabase.java:25)
61    at com.emirhalici.notetakingappnvvmexample.NoteRepository.&lt;init&gt;(NoteRepository.java:15)
62    at com.emirhalici.notetakingappnvvmexample.NoteViewModel.&lt;init&gt;(NoteViewModel.java:19)
63    at java.lang.reflect.Constructor.newInstance0(Native Method) 
64    at java.lang.reflect.Constructor.newInstance(Constructor.java:343) 
65    at androidx.lifecycle.ViewModelProvider$AndroidViewModelFactory.create(ViewModelProvider.java:267) 
66    at androidx.lifecycle.ViewModelProvider.get(ViewModelProvider.java:187) 
67    at androidx.lifecycle.ViewModelProvider.get(ViewModelProvider.java:150) 
68    at com.emirhalici.notetakingappnvvmexample.MainActivity.onCreate(MainActivity.java:26) 
69    at android.app.Activity.performCreate(Activity.java:8000) 
70    at android.app.Activity.performCreate(Activity.java:7984) 
71    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1309) 
72    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3422) 
73    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601) 
74    at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85) 
75    at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) 
76    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) 
77    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066) 
78    at android.os.Handler.dispatchMessage(Handler.java:106) 
79    at android.os.Looper.loop(Looper.java:223) 
80    at android.app.ActivityThread.main(ActivityThread.java:7656) 
81    at java.lang.reflect.Method.invoke(Native Method) 
82    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592) 
83    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947) 
84public class MainActivity extends AppCompatActivity {
85private NoteViewModel noteViewModel;
86
87@Override
88protected void onCreate(Bundle savedInstanceState) {
89    super.onCreate(savedInstanceState);
90    setContentView(R.layout.activity_main);
91
92    // these didn't work
93    //noteViewModel = new ViewModelProvider(this, ViewModelProvider.AndroidViewModelFactory.getInstance(this.getApplication())).get(NoteViewModel.class);
94    //noteViewModel = new ViewModelProvider(this).get(NoteViewModel.class);
95    //noteViewModel = ViewModelProviders.of(this).get(NoteViewModel.class);
96    // i tried this but this don't work either
97    noteViewModel = new ViewModelProvider(this,
98            ViewModelProvider.AndroidViewModelFactory.getInstance(this.getApplication())).get(NoteViewModel.class);
99    noteViewModel.getAllNotes().observe(this, new Observer&lt;List&lt;Note&gt;&gt;() {
100        @Override
101        public void onChanged(List&lt;Note&gt; notes) {
102            // update RecyclerView
103            Toast.makeText(MainActivity.this, &quot;onChanged&quot;, Toast.LENGTH_SHORT).show();
104        }
105    });
106} }
107

Note.java (entity class)

1    Process: com.emirhalici.notetakingappnvvmexample, PID: 17577
2java.lang.RuntimeException: Unable to start activity ComponentInfo{com.emirhalici.notetakingappnvvmexample/com.emirhalici.notetakingappnvvmexample.MainActivity}: java.lang.RuntimeException: Cannot create an instance of class com.emirhalici.notetakingappnvvmexample.NoteViewModel
3    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3449)
4    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601)
5    at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
6    at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
7    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
8    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066)
9    at android.os.Handler.dispatchMessage(Handler.java:106)
10    at android.os.Looper.loop(Looper.java:223)
11    at android.app.ActivityThread.main(ActivityThread.java:7656)
12    at java.lang.reflect.Method.invoke(Native Method)
13    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
14    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
15 Caused by: java.lang.RuntimeException: Cannot create an instance of class com.emirhalici.notetakingappnvvmexample.NoteViewModel
16    at androidx.lifecycle.ViewModelProvider$AndroidViewModelFactory.create(ViewModelProvider.java:275)
17    at androidx.lifecycle.ViewModelProvider.get(ViewModelProvider.java:187)
18    at androidx.lifecycle.ViewModelProvider.get(ViewModelProvider.java:150)
19    at com.emirhalici.notetakingappnvvmexample.MainActivity.onCreate(MainActivity.java:26)
20    at android.app.Activity.performCreate(Activity.java:8000)
21    at android.app.Activity.performCreate(Activity.java:7984)
22    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1309)
23    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3422)
24    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601) 
25    at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85) 
26    at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) 
27    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) 
28    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066) 
29    at android.os.Handler.dispatchMessage(Handler.java:106) 
30    at android.os.Looper.loop(Looper.java:223) 
31    at android.app.ActivityThread.main(ActivityThread.java:7656) 
32    at java.lang.reflect.Method.invoke(Native Method) 
33    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592) 
34    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947) 
35 Caused by: java.lang.reflect.InvocationTargetException
36    at java.lang.reflect.Constructor.newInstance0(Native Method)
37    at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
38    at androidx.lifecycle.ViewModelProvider$AndroidViewModelFactory.create(ViewModelProvider.java:267)
39    at androidx.lifecycle.ViewModelProvider.get(ViewModelProvider.java:187) 
40    at androidx.lifecycle.ViewModelProvider.get(ViewModelProvider.java:150) 
41    at com.emirhalici.notetakingappnvvmexample.MainActivity.onCreate(MainActivity.java:26) 
42    at android.app.Activity.performCreate(Activity.java:8000) 
43    at android.app.Activity.performCreate(Activity.java:7984) 
44    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1309) 
45    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3422) 
46    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601) 
47    at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85) 
48    at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) 
49    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) 
50    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066) 
51    at android.os.Handler.dispatchMessage(Handler.java:106) 
52    at android.os.Looper.loop(Looper.java:223) 
53    at android.app.ActivityThread.main(ActivityThread.java:7656) 
54    at java.lang.reflect.Method.invoke(Native Method) 
55    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592) 
56    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947) 
57 Caused by: java.lang.RuntimeException: cannot find implementation for com.emirhalici.notetakingappnvvmexample.NoteDatabase. NoteDatabase_Impl does not exist
58    at androidx.room.Room.getGeneratedImplementation(Room.java:97)
59    at androidx.room.RoomDatabase$Builder.build(RoomDatabase.java:1358)
60    at com.emirhalici.notetakingappnvvmexample.NoteDatabase.getInstance(NoteDatabase.java:25)
61    at com.emirhalici.notetakingappnvvmexample.NoteRepository.&lt;init&gt;(NoteRepository.java:15)
62    at com.emirhalici.notetakingappnvvmexample.NoteViewModel.&lt;init&gt;(NoteViewModel.java:19)
63    at java.lang.reflect.Constructor.newInstance0(Native Method) 
64    at java.lang.reflect.Constructor.newInstance(Constructor.java:343) 
65    at androidx.lifecycle.ViewModelProvider$AndroidViewModelFactory.create(ViewModelProvider.java:267) 
66    at androidx.lifecycle.ViewModelProvider.get(ViewModelProvider.java:187) 
67    at androidx.lifecycle.ViewModelProvider.get(ViewModelProvider.java:150) 
68    at com.emirhalici.notetakingappnvvmexample.MainActivity.onCreate(MainActivity.java:26) 
69    at android.app.Activity.performCreate(Activity.java:8000) 
70    at android.app.Activity.performCreate(Activity.java:7984) 
71    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1309) 
72    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3422) 
73    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601) 
74    at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85) 
75    at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) 
76    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) 
77    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066) 
78    at android.os.Handler.dispatchMessage(Handler.java:106) 
79    at android.os.Looper.loop(Looper.java:223) 
80    at android.app.ActivityThread.main(ActivityThread.java:7656) 
81    at java.lang.reflect.Method.invoke(Native Method) 
82    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592) 
83    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947) 
84public class MainActivity extends AppCompatActivity {
85private NoteViewModel noteViewModel;
86
87@Override
88protected void onCreate(Bundle savedInstanceState) {
89    super.onCreate(savedInstanceState);
90    setContentView(R.layout.activity_main);
91
92    // these didn't work
93    //noteViewModel = new ViewModelProvider(this, ViewModelProvider.AndroidViewModelFactory.getInstance(this.getApplication())).get(NoteViewModel.class);
94    //noteViewModel = new ViewModelProvider(this).get(NoteViewModel.class);
95    //noteViewModel = ViewModelProviders.of(this).get(NoteViewModel.class);
96    // i tried this but this don't work either
97    noteViewModel = new ViewModelProvider(this,
98            ViewModelProvider.AndroidViewModelFactory.getInstance(this.getApplication())).get(NoteViewModel.class);
99    noteViewModel.getAllNotes().observe(this, new Observer&lt;List&lt;Note&gt;&gt;() {
100        @Override
101        public void onChanged(List&lt;Note&gt; notes) {
102            // update RecyclerView
103            Toast.makeText(MainActivity.this, &quot;onChanged&quot;, Toast.LENGTH_SHORT).show();
104        }
105    });
106} }
107@Entity(tableName = &quot;note_table&quot;)
108public class Note {
109
110@PrimaryKey(autoGenerate = true)
111private int id;
112
113private String title;
114private String description;
115private int priority;
116
117// getters
118public int getId() {
119    return id;
120}
121
122public String getTitle() {
123    return title;
124}
125
126public String getDescription() {
127    return description;
128}
129
130public int getPriority() {
131    return priority;
132}
133
134// id setter
135public void setId(int id) {
136    this.id = id;
137}
138
139// constructor
140public Note(String title, String description, int priority) {
141    this.title = title;
142    this.description = description;
143    this.priority = priority;
144}
145
146}
147

NoteDao.java

1    Process: com.emirhalici.notetakingappnvvmexample, PID: 17577
2java.lang.RuntimeException: Unable to start activity ComponentInfo{com.emirhalici.notetakingappnvvmexample/com.emirhalici.notetakingappnvvmexample.MainActivity}: java.lang.RuntimeException: Cannot create an instance of class com.emirhalici.notetakingappnvvmexample.NoteViewModel
3    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3449)
4    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601)
5    at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
6    at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
7    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
8    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066)
9    at android.os.Handler.dispatchMessage(Handler.java:106)
10    at android.os.Looper.loop(Looper.java:223)
11    at android.app.ActivityThread.main(ActivityThread.java:7656)
12    at java.lang.reflect.Method.invoke(Native Method)
13    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
14    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
15 Caused by: java.lang.RuntimeException: Cannot create an instance of class com.emirhalici.notetakingappnvvmexample.NoteViewModel
16    at androidx.lifecycle.ViewModelProvider$AndroidViewModelFactory.create(ViewModelProvider.java:275)
17    at androidx.lifecycle.ViewModelProvider.get(ViewModelProvider.java:187)
18    at androidx.lifecycle.ViewModelProvider.get(ViewModelProvider.java:150)
19    at com.emirhalici.notetakingappnvvmexample.MainActivity.onCreate(MainActivity.java:26)
20    at android.app.Activity.performCreate(Activity.java:8000)
21    at android.app.Activity.performCreate(Activity.java:7984)
22    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1309)
23    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3422)
24    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601) 
25    at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85) 
26    at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) 
27    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) 
28    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066) 
29    at android.os.Handler.dispatchMessage(Handler.java:106) 
30    at android.os.Looper.loop(Looper.java:223) 
31    at android.app.ActivityThread.main(ActivityThread.java:7656) 
32    at java.lang.reflect.Method.invoke(Native Method) 
33    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592) 
34    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947) 
35 Caused by: java.lang.reflect.InvocationTargetException
36    at java.lang.reflect.Constructor.newInstance0(Native Method)
37    at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
38    at androidx.lifecycle.ViewModelProvider$AndroidViewModelFactory.create(ViewModelProvider.java:267)
39    at androidx.lifecycle.ViewModelProvider.get(ViewModelProvider.java:187) 
40    at androidx.lifecycle.ViewModelProvider.get(ViewModelProvider.java:150) 
41    at com.emirhalici.notetakingappnvvmexample.MainActivity.onCreate(MainActivity.java:26) 
42    at android.app.Activity.performCreate(Activity.java:8000) 
43    at android.app.Activity.performCreate(Activity.java:7984) 
44    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1309) 
45    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3422) 
46    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601) 
47    at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85) 
48    at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) 
49    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) 
50    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066) 
51    at android.os.Handler.dispatchMessage(Handler.java:106) 
52    at android.os.Looper.loop(Looper.java:223) 
53    at android.app.ActivityThread.main(ActivityThread.java:7656) 
54    at java.lang.reflect.Method.invoke(Native Method) 
55    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592) 
56    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947) 
57 Caused by: java.lang.RuntimeException: cannot find implementation for com.emirhalici.notetakingappnvvmexample.NoteDatabase. NoteDatabase_Impl does not exist
58    at androidx.room.Room.getGeneratedImplementation(Room.java:97)
59    at androidx.room.RoomDatabase$Builder.build(RoomDatabase.java:1358)
60    at com.emirhalici.notetakingappnvvmexample.NoteDatabase.getInstance(NoteDatabase.java:25)
61    at com.emirhalici.notetakingappnvvmexample.NoteRepository.&lt;init&gt;(NoteRepository.java:15)
62    at com.emirhalici.notetakingappnvvmexample.NoteViewModel.&lt;init&gt;(NoteViewModel.java:19)
63    at java.lang.reflect.Constructor.newInstance0(Native Method) 
64    at java.lang.reflect.Constructor.newInstance(Constructor.java:343) 
65    at androidx.lifecycle.ViewModelProvider$AndroidViewModelFactory.create(ViewModelProvider.java:267) 
66    at androidx.lifecycle.ViewModelProvider.get(ViewModelProvider.java:187) 
67    at androidx.lifecycle.ViewModelProvider.get(ViewModelProvider.java:150) 
68    at com.emirhalici.notetakingappnvvmexample.MainActivity.onCreate(MainActivity.java:26) 
69    at android.app.Activity.performCreate(Activity.java:8000) 
70    at android.app.Activity.performCreate(Activity.java:7984) 
71    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1309) 
72    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3422) 
73    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601) 
74    at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85) 
75    at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) 
76    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) 
77    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066) 
78    at android.os.Handler.dispatchMessage(Handler.java:106) 
79    at android.os.Looper.loop(Looper.java:223) 
80    at android.app.ActivityThread.main(ActivityThread.java:7656) 
81    at java.lang.reflect.Method.invoke(Native Method) 
82    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592) 
83    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947) 
84public class MainActivity extends AppCompatActivity {
85private NoteViewModel noteViewModel;
86
87@Override
88protected void onCreate(Bundle savedInstanceState) {
89    super.onCreate(savedInstanceState);
90    setContentView(R.layout.activity_main);
91
92    // these didn't work
93    //noteViewModel = new ViewModelProvider(this, ViewModelProvider.AndroidViewModelFactory.getInstance(this.getApplication())).get(NoteViewModel.class);
94    //noteViewModel = new ViewModelProvider(this).get(NoteViewModel.class);
95    //noteViewModel = ViewModelProviders.of(this).get(NoteViewModel.class);
96    // i tried this but this don't work either
97    noteViewModel = new ViewModelProvider(this,
98            ViewModelProvider.AndroidViewModelFactory.getInstance(this.getApplication())).get(NoteViewModel.class);
99    noteViewModel.getAllNotes().observe(this, new Observer&lt;List&lt;Note&gt;&gt;() {
100        @Override
101        public void onChanged(List&lt;Note&gt; notes) {
102            // update RecyclerView
103            Toast.makeText(MainActivity.this, &quot;onChanged&quot;, Toast.LENGTH_SHORT).show();
104        }
105    });
106} }
107@Entity(tableName = &quot;note_table&quot;)
108public class Note {
109
110@PrimaryKey(autoGenerate = true)
111private int id;
112
113private String title;
114private String description;
115private int priority;
116
117// getters
118public int getId() {
119    return id;
120}
121
122public String getTitle() {
123    return title;
124}
125
126public String getDescription() {
127    return description;
128}
129
130public int getPriority() {
131    return priority;
132}
133
134// id setter
135public void setId(int id) {
136    this.id = id;
137}
138
139// constructor
140public Note(String title, String description, int priority) {
141    this.title = title;
142    this.description = description;
143    this.priority = priority;
144}
145
146}
147@Dao
148public interface NoteDao {
149
150@Insert
151void insert(Note note);
152
153@Update
154void update(Note note);
155
156@Delete
157void delete(Note note);
158
159@Query(&quot;DELETE FROM note_table&quot;)
160void deleteAll();
161
162@Query(&quot;SELECT * FROM note_table ORDER BY priority DESC&quot;)
163LiveData&lt;List&lt;Note&gt;&gt; getAllNotes();
164
165}
166

NoteDatabase.java

1    Process: com.emirhalici.notetakingappnvvmexample, PID: 17577
2java.lang.RuntimeException: Unable to start activity ComponentInfo{com.emirhalici.notetakingappnvvmexample/com.emirhalici.notetakingappnvvmexample.MainActivity}: java.lang.RuntimeException: Cannot create an instance of class com.emirhalici.notetakingappnvvmexample.NoteViewModel
3    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3449)
4    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601)
5    at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
6    at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
7    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
8    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066)
9    at android.os.Handler.dispatchMessage(Handler.java:106)
10    at android.os.Looper.loop(Looper.java:223)
11    at android.app.ActivityThread.main(ActivityThread.java:7656)
12    at java.lang.reflect.Method.invoke(Native Method)
13    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
14    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
15 Caused by: java.lang.RuntimeException: Cannot create an instance of class com.emirhalici.notetakingappnvvmexample.NoteViewModel
16    at androidx.lifecycle.ViewModelProvider$AndroidViewModelFactory.create(ViewModelProvider.java:275)
17    at androidx.lifecycle.ViewModelProvider.get(ViewModelProvider.java:187)
18    at androidx.lifecycle.ViewModelProvider.get(ViewModelProvider.java:150)
19    at com.emirhalici.notetakingappnvvmexample.MainActivity.onCreate(MainActivity.java:26)
20    at android.app.Activity.performCreate(Activity.java:8000)
21    at android.app.Activity.performCreate(Activity.java:7984)
22    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1309)
23    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3422)
24    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601) 
25    at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85) 
26    at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) 
27    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) 
28    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066) 
29    at android.os.Handler.dispatchMessage(Handler.java:106) 
30    at android.os.Looper.loop(Looper.java:223) 
31    at android.app.ActivityThread.main(ActivityThread.java:7656) 
32    at java.lang.reflect.Method.invoke(Native Method) 
33    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592) 
34    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947) 
35 Caused by: java.lang.reflect.InvocationTargetException
36    at java.lang.reflect.Constructor.newInstance0(Native Method)
37    at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
38    at androidx.lifecycle.ViewModelProvider$AndroidViewModelFactory.create(ViewModelProvider.java:267)
39    at androidx.lifecycle.ViewModelProvider.get(ViewModelProvider.java:187) 
40    at androidx.lifecycle.ViewModelProvider.get(ViewModelProvider.java:150) 
41    at com.emirhalici.notetakingappnvvmexample.MainActivity.onCreate(MainActivity.java:26) 
42    at android.app.Activity.performCreate(Activity.java:8000) 
43    at android.app.Activity.performCreate(Activity.java:7984) 
44    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1309) 
45    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3422) 
46    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601) 
47    at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85) 
48    at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) 
49    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) 
50    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066) 
51    at android.os.Handler.dispatchMessage(Handler.java:106) 
52    at android.os.Looper.loop(Looper.java:223) 
53    at android.app.ActivityThread.main(ActivityThread.java:7656) 
54    at java.lang.reflect.Method.invoke(Native Method) 
55    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592) 
56    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947) 
57 Caused by: java.lang.RuntimeException: cannot find implementation for com.emirhalici.notetakingappnvvmexample.NoteDatabase. NoteDatabase_Impl does not exist
58    at androidx.room.Room.getGeneratedImplementation(Room.java:97)
59    at androidx.room.RoomDatabase$Builder.build(RoomDatabase.java:1358)
60    at com.emirhalici.notetakingappnvvmexample.NoteDatabase.getInstance(NoteDatabase.java:25)
61    at com.emirhalici.notetakingappnvvmexample.NoteRepository.&lt;init&gt;(NoteRepository.java:15)
62    at com.emirhalici.notetakingappnvvmexample.NoteViewModel.&lt;init&gt;(NoteViewModel.java:19)
63    at java.lang.reflect.Constructor.newInstance0(Native Method) 
64    at java.lang.reflect.Constructor.newInstance(Constructor.java:343) 
65    at androidx.lifecycle.ViewModelProvider$AndroidViewModelFactory.create(ViewModelProvider.java:267) 
66    at androidx.lifecycle.ViewModelProvider.get(ViewModelProvider.java:187) 
67    at androidx.lifecycle.ViewModelProvider.get(ViewModelProvider.java:150) 
68    at com.emirhalici.notetakingappnvvmexample.MainActivity.onCreate(MainActivity.java:26) 
69    at android.app.Activity.performCreate(Activity.java:8000) 
70    at android.app.Activity.performCreate(Activity.java:7984) 
71    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1309) 
72    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3422) 
73    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601) 
74    at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85) 
75    at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) 
76    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) 
77    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066) 
78    at android.os.Handler.dispatchMessage(Handler.java:106) 
79    at android.os.Looper.loop(Looper.java:223) 
80    at android.app.ActivityThread.main(ActivityThread.java:7656) 
81    at java.lang.reflect.Method.invoke(Native Method) 
82    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592) 
83    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947) 
84public class MainActivity extends AppCompatActivity {
85private NoteViewModel noteViewModel;
86
87@Override
88protected void onCreate(Bundle savedInstanceState) {
89    super.onCreate(savedInstanceState);
90    setContentView(R.layout.activity_main);
91
92    // these didn't work
93    //noteViewModel = new ViewModelProvider(this, ViewModelProvider.AndroidViewModelFactory.getInstance(this.getApplication())).get(NoteViewModel.class);
94    //noteViewModel = new ViewModelProvider(this).get(NoteViewModel.class);
95    //noteViewModel = ViewModelProviders.of(this).get(NoteViewModel.class);
96    // i tried this but this don't work either
97    noteViewModel = new ViewModelProvider(this,
98            ViewModelProvider.AndroidViewModelFactory.getInstance(this.getApplication())).get(NoteViewModel.class);
99    noteViewModel.getAllNotes().observe(this, new Observer&lt;List&lt;Note&gt;&gt;() {
100        @Override
101        public void onChanged(List&lt;Note&gt; notes) {
102            // update RecyclerView
103            Toast.makeText(MainActivity.this, &quot;onChanged&quot;, Toast.LENGTH_SHORT).show();
104        }
105    });
106} }
107@Entity(tableName = &quot;note_table&quot;)
108public class Note {
109
110@PrimaryKey(autoGenerate = true)
111private int id;
112
113private String title;
114private String description;
115private int priority;
116
117// getters
118public int getId() {
119    return id;
120}
121
122public String getTitle() {
123    return title;
124}
125
126public String getDescription() {
127    return description;
128}
129
130public int getPriority() {
131    return priority;
132}
133
134// id setter
135public void setId(int id) {
136    this.id = id;
137}
138
139// constructor
140public Note(String title, String description, int priority) {
141    this.title = title;
142    this.description = description;
143    this.priority = priority;
144}
145
146}
147@Dao
148public interface NoteDao {
149
150@Insert
151void insert(Note note);
152
153@Update
154void update(Note note);
155
156@Delete
157void delete(Note note);
158
159@Query(&quot;DELETE FROM note_table&quot;)
160void deleteAll();
161
162@Query(&quot;SELECT * FROM note_table ORDER BY priority DESC&quot;)
163LiveData&lt;List&lt;Note&gt;&gt; getAllNotes();
164
165}
166@Database(entities = Note.class, version = 1)
167public abstract class NoteDatabase extends RoomDatabase {
168
169private static NoteDatabase instance;
170
171public abstract NoteDao noteDao();
172
173public static synchronized NoteDatabase getInstance(Context context) {
174    if (instance == null) {
175        instance = Room.databaseBuilder(context.getApplicationContext(),
176                NoteDatabase.class, &quot;note_database&quot;)
177                .fallbackToDestructiveMigration()
178                .addCallback(roomCallback)
179                .build();
180    }
181    return instance;
182}
183
184private static RoomDatabase.Callback roomCallback = new RoomDatabase.Callback() {
185    @Override
186    public void onCreate(@NonNull SupportSQLiteDatabase db) {
187        super.onCreate(db);
188        new PopulateDbAsyncTask(instance).execute();
189    }
190};
191
192private static class PopulateDbAsyncTask extends AsyncTask&lt;Void, Void, Void&gt; {
193    private NoteDao noteDao;
194    private PopulateDbAsyncTask(NoteDatabase db) {
195        noteDao = db.noteDao();
196    }
197
198    @Override
199    protected Void doInBackground(Void... voids) {
200        noteDao.insert(new Note(&quot;Title 1&quot;,&quot;Description 1&quot;, 1));
201        noteDao.insert(new Note(&quot;Title 2&quot;,&quot;Description 2&quot;, 2));
202        noteDao.insert(new Note(&quot;Title 3&quot;,&quot;Description 3&quot;, 3));
203        noteDao.insert(new Note(&quot;Title 4&quot;,&quot;Description 4&quot;, 1));
204        noteDao.insert(new Note(&quot;Title 5&quot;,&quot;Description 5&quot;, 2));
205        noteDao.insert(new Note(&quot;Title 6&quot;,&quot;Description 6&quot;, 4));
206        return null;
207    }
208}
209}
210

NoteRepository.java

1    Process: com.emirhalici.notetakingappnvvmexample, PID: 17577
2java.lang.RuntimeException: Unable to start activity ComponentInfo{com.emirhalici.notetakingappnvvmexample/com.emirhalici.notetakingappnvvmexample.MainActivity}: java.lang.RuntimeException: Cannot create an instance of class com.emirhalici.notetakingappnvvmexample.NoteViewModel
3    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3449)
4    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601)
5    at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
6    at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
7    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
8    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066)
9    at android.os.Handler.dispatchMessage(Handler.java:106)
10    at android.os.Looper.loop(Looper.java:223)
11    at android.app.ActivityThread.main(ActivityThread.java:7656)
12    at java.lang.reflect.Method.invoke(Native Method)
13    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
14    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
15 Caused by: java.lang.RuntimeException: Cannot create an instance of class com.emirhalici.notetakingappnvvmexample.NoteViewModel
16    at androidx.lifecycle.ViewModelProvider$AndroidViewModelFactory.create(ViewModelProvider.java:275)
17    at androidx.lifecycle.ViewModelProvider.get(ViewModelProvider.java:187)
18    at androidx.lifecycle.ViewModelProvider.get(ViewModelProvider.java:150)
19    at com.emirhalici.notetakingappnvvmexample.MainActivity.onCreate(MainActivity.java:26)
20    at android.app.Activity.performCreate(Activity.java:8000)
21    at android.app.Activity.performCreate(Activity.java:7984)
22    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1309)
23    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3422)
24    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601) 
25    at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85) 
26    at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) 
27    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) 
28    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066) 
29    at android.os.Handler.dispatchMessage(Handler.java:106) 
30    at android.os.Looper.loop(Looper.java:223) 
31    at android.app.ActivityThread.main(ActivityThread.java:7656) 
32    at java.lang.reflect.Method.invoke(Native Method) 
33    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592) 
34    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947) 
35 Caused by: java.lang.reflect.InvocationTargetException
36    at java.lang.reflect.Constructor.newInstance0(Native Method)
37    at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
38    at androidx.lifecycle.ViewModelProvider$AndroidViewModelFactory.create(ViewModelProvider.java:267)
39    at androidx.lifecycle.ViewModelProvider.get(ViewModelProvider.java:187) 
40    at androidx.lifecycle.ViewModelProvider.get(ViewModelProvider.java:150) 
41    at com.emirhalici.notetakingappnvvmexample.MainActivity.onCreate(MainActivity.java:26) 
42    at android.app.Activity.performCreate(Activity.java:8000) 
43    at android.app.Activity.performCreate(Activity.java:7984) 
44    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1309) 
45    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3422) 
46    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601) 
47    at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85) 
48    at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) 
49    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) 
50    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066) 
51    at android.os.Handler.dispatchMessage(Handler.java:106) 
52    at android.os.Looper.loop(Looper.java:223) 
53    at android.app.ActivityThread.main(ActivityThread.java:7656) 
54    at java.lang.reflect.Method.invoke(Native Method) 
55    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592) 
56    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947) 
57 Caused by: java.lang.RuntimeException: cannot find implementation for com.emirhalici.notetakingappnvvmexample.NoteDatabase. NoteDatabase_Impl does not exist
58    at androidx.room.Room.getGeneratedImplementation(Room.java:97)
59    at androidx.room.RoomDatabase$Builder.build(RoomDatabase.java:1358)
60    at com.emirhalici.notetakingappnvvmexample.NoteDatabase.getInstance(NoteDatabase.java:25)
61    at com.emirhalici.notetakingappnvvmexample.NoteRepository.&lt;init&gt;(NoteRepository.java:15)
62    at com.emirhalici.notetakingappnvvmexample.NoteViewModel.&lt;init&gt;(NoteViewModel.java:19)
63    at java.lang.reflect.Constructor.newInstance0(Native Method) 
64    at java.lang.reflect.Constructor.newInstance(Constructor.java:343) 
65    at androidx.lifecycle.ViewModelProvider$AndroidViewModelFactory.create(ViewModelProvider.java:267) 
66    at androidx.lifecycle.ViewModelProvider.get(ViewModelProvider.java:187) 
67    at androidx.lifecycle.ViewModelProvider.get(ViewModelProvider.java:150) 
68    at com.emirhalici.notetakingappnvvmexample.MainActivity.onCreate(MainActivity.java:26) 
69    at android.app.Activity.performCreate(Activity.java:8000) 
70    at android.app.Activity.performCreate(Activity.java:7984) 
71    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1309) 
72    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3422) 
73    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601) 
74    at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85) 
75    at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) 
76    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) 
77    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066) 
78    at android.os.Handler.dispatchMessage(Handler.java:106) 
79    at android.os.Looper.loop(Looper.java:223) 
80    at android.app.ActivityThread.main(ActivityThread.java:7656) 
81    at java.lang.reflect.Method.invoke(Native Method) 
82    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592) 
83    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947) 
84public class MainActivity extends AppCompatActivity {
85private NoteViewModel noteViewModel;
86
87@Override
88protected void onCreate(Bundle savedInstanceState) {
89    super.onCreate(savedInstanceState);
90    setContentView(R.layout.activity_main);
91
92    // these didn't work
93    //noteViewModel = new ViewModelProvider(this, ViewModelProvider.AndroidViewModelFactory.getInstance(this.getApplication())).get(NoteViewModel.class);
94    //noteViewModel = new ViewModelProvider(this).get(NoteViewModel.class);
95    //noteViewModel = ViewModelProviders.of(this).get(NoteViewModel.class);
96    // i tried this but this don't work either
97    noteViewModel = new ViewModelProvider(this,
98            ViewModelProvider.AndroidViewModelFactory.getInstance(this.getApplication())).get(NoteViewModel.class);
99    noteViewModel.getAllNotes().observe(this, new Observer&lt;List&lt;Note&gt;&gt;() {
100        @Override
101        public void onChanged(List&lt;Note&gt; notes) {
102            // update RecyclerView
103            Toast.makeText(MainActivity.this, &quot;onChanged&quot;, Toast.LENGTH_SHORT).show();
104        }
105    });
106} }
107@Entity(tableName = &quot;note_table&quot;)
108public class Note {
109
110@PrimaryKey(autoGenerate = true)
111private int id;
112
113private String title;
114private String description;
115private int priority;
116
117// getters
118public int getId() {
119    return id;
120}
121
122public String getTitle() {
123    return title;
124}
125
126public String getDescription() {
127    return description;
128}
129
130public int getPriority() {
131    return priority;
132}
133
134// id setter
135public void setId(int id) {
136    this.id = id;
137}
138
139// constructor
140public Note(String title, String description, int priority) {
141    this.title = title;
142    this.description = description;
143    this.priority = priority;
144}
145
146}
147@Dao
148public interface NoteDao {
149
150@Insert
151void insert(Note note);
152
153@Update
154void update(Note note);
155
156@Delete
157void delete(Note note);
158
159@Query(&quot;DELETE FROM note_table&quot;)
160void deleteAll();
161
162@Query(&quot;SELECT * FROM note_table ORDER BY priority DESC&quot;)
163LiveData&lt;List&lt;Note&gt;&gt; getAllNotes();
164
165}
166@Database(entities = Note.class, version = 1)
167public abstract class NoteDatabase extends RoomDatabase {
168
169private static NoteDatabase instance;
170
171public abstract NoteDao noteDao();
172
173public static synchronized NoteDatabase getInstance(Context context) {
174    if (instance == null) {
175        instance = Room.databaseBuilder(context.getApplicationContext(),
176                NoteDatabase.class, &quot;note_database&quot;)
177                .fallbackToDestructiveMigration()
178                .addCallback(roomCallback)
179                .build();
180    }
181    return instance;
182}
183
184private static RoomDatabase.Callback roomCallback = new RoomDatabase.Callback() {
185    @Override
186    public void onCreate(@NonNull SupportSQLiteDatabase db) {
187        super.onCreate(db);
188        new PopulateDbAsyncTask(instance).execute();
189    }
190};
191
192private static class PopulateDbAsyncTask extends AsyncTask&lt;Void, Void, Void&gt; {
193    private NoteDao noteDao;
194    private PopulateDbAsyncTask(NoteDatabase db) {
195        noteDao = db.noteDao();
196    }
197
198    @Override
199    protected Void doInBackground(Void... voids) {
200        noteDao.insert(new Note(&quot;Title 1&quot;,&quot;Description 1&quot;, 1));
201        noteDao.insert(new Note(&quot;Title 2&quot;,&quot;Description 2&quot;, 2));
202        noteDao.insert(new Note(&quot;Title 3&quot;,&quot;Description 3&quot;, 3));
203        noteDao.insert(new Note(&quot;Title 4&quot;,&quot;Description 4&quot;, 1));
204        noteDao.insert(new Note(&quot;Title 5&quot;,&quot;Description 5&quot;, 2));
205        noteDao.insert(new Note(&quot;Title 6&quot;,&quot;Description 6&quot;, 4));
206        return null;
207    }
208}
209}
210public class NoteRepository {
211private NoteDao noteDao;
212private LiveData&lt;List&lt;Note&gt;&gt; allNotes;
213
214public NoteRepository(Application application) {
215    NoteDatabase database = NoteDatabase.getInstance(application);
216    noteDao = database.noteDao();
217    allNotes = noteDao.getAllNotes();
218}
219
220public void insert(Note note) {
221    new InsertNoteAsyncTask(noteDao).execute(note);
222}
223
224public void update(Note note) {
225    new UpdateNoteAsyncTask(noteDao).execute(note);
226}
227
228public void delete(Note note) {
229    new DeleteNoteAsyncTask(noteDao).execute(note);
230}
231
232public void deleteAll() {
233    new DeleteAllNotesAsyncTask(noteDao).execute();
234}
235
236public LiveData&lt;List&lt;Note&gt;&gt; getAllNotes() {
237    return allNotes;
238}
239
240private static class InsertNoteAsyncTask extends AsyncTask&lt;Note, Void, Void&gt; {
241    private NoteDao noteDao;
242
243    private InsertNoteAsyncTask(NoteDao noteDao) {
244        this.noteDao = noteDao;
245    }
246
247    @Override
248    protected Void doInBackground(Note... notes) {
249        noteDao.insert(notes[0]);
250        return null;
251    }
252}
253
254private static class UpdateNoteAsyncTask extends AsyncTask&lt;Note, Void, Void&gt; {
255    private NoteDao noteDao;
256
257    private UpdateNoteAsyncTask(NoteDao noteDao) {
258        this.noteDao = noteDao;
259    }
260
261    @Override
262    protected Void doInBackground(Note... notes) {
263        noteDao.update(notes[0]);
264        return null;
265    }
266}
267
268private static class DeleteNoteAsyncTask extends AsyncTask&lt;Note, Void, Void&gt; {
269    private NoteDao noteDao;
270
271    private DeleteNoteAsyncTask(NoteDao noteDao) {
272        this.noteDao = noteDao;
273    }
274
275    @Override
276    protected Void doInBackground(Note... notes) {
277        noteDao.delete(notes[0]);
278        return null;
279    }
280}
281
282private static class DeleteAllNotesAsyncTask extends AsyncTask&lt;Note, Void, Void&gt; {
283    private NoteDao noteDao;
284
285    private DeleteAllNotesAsyncTask(NoteDao noteDao) {
286        this.noteDao = noteDao;
287    }
288
289    @Override
290    protected Void doInBackground(Note... voids) {
291        noteDao.deleteAll();
292        return null;
293    }
294}
295}
296

NoteViewModel.java

1    Process: com.emirhalici.notetakingappnvvmexample, PID: 17577
2java.lang.RuntimeException: Unable to start activity ComponentInfo{com.emirhalici.notetakingappnvvmexample/com.emirhalici.notetakingappnvvmexample.MainActivity}: java.lang.RuntimeException: Cannot create an instance of class com.emirhalici.notetakingappnvvmexample.NoteViewModel
3    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3449)
4    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601)
5    at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
6    at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
7    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
8    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066)
9    at android.os.Handler.dispatchMessage(Handler.java:106)
10    at android.os.Looper.loop(Looper.java:223)
11    at android.app.ActivityThread.main(ActivityThread.java:7656)
12    at java.lang.reflect.Method.invoke(Native Method)
13    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
14    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
15 Caused by: java.lang.RuntimeException: Cannot create an instance of class com.emirhalici.notetakingappnvvmexample.NoteViewModel
16    at androidx.lifecycle.ViewModelProvider$AndroidViewModelFactory.create(ViewModelProvider.java:275)
17    at androidx.lifecycle.ViewModelProvider.get(ViewModelProvider.java:187)
18    at androidx.lifecycle.ViewModelProvider.get(ViewModelProvider.java:150)
19    at com.emirhalici.notetakingappnvvmexample.MainActivity.onCreate(MainActivity.java:26)
20    at android.app.Activity.performCreate(Activity.java:8000)
21    at android.app.Activity.performCreate(Activity.java:7984)
22    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1309)
23    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3422)
24    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601) 
25    at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85) 
26    at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) 
27    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) 
28    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066) 
29    at android.os.Handler.dispatchMessage(Handler.java:106) 
30    at android.os.Looper.loop(Looper.java:223) 
31    at android.app.ActivityThread.main(ActivityThread.java:7656) 
32    at java.lang.reflect.Method.invoke(Native Method) 
33    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592) 
34    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947) 
35 Caused by: java.lang.reflect.InvocationTargetException
36    at java.lang.reflect.Constructor.newInstance0(Native Method)
37    at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
38    at androidx.lifecycle.ViewModelProvider$AndroidViewModelFactory.create(ViewModelProvider.java:267)
39    at androidx.lifecycle.ViewModelProvider.get(ViewModelProvider.java:187) 
40    at androidx.lifecycle.ViewModelProvider.get(ViewModelProvider.java:150) 
41    at com.emirhalici.notetakingappnvvmexample.MainActivity.onCreate(MainActivity.java:26) 
42    at android.app.Activity.performCreate(Activity.java:8000) 
43    at android.app.Activity.performCreate(Activity.java:7984) 
44    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1309) 
45    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3422) 
46    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601) 
47    at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85) 
48    at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) 
49    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) 
50    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066) 
51    at android.os.Handler.dispatchMessage(Handler.java:106) 
52    at android.os.Looper.loop(Looper.java:223) 
53    at android.app.ActivityThread.main(ActivityThread.java:7656) 
54    at java.lang.reflect.Method.invoke(Native Method) 
55    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592) 
56    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947) 
57 Caused by: java.lang.RuntimeException: cannot find implementation for com.emirhalici.notetakingappnvvmexample.NoteDatabase. NoteDatabase_Impl does not exist
58    at androidx.room.Room.getGeneratedImplementation(Room.java:97)
59    at androidx.room.RoomDatabase$Builder.build(RoomDatabase.java:1358)
60    at com.emirhalici.notetakingappnvvmexample.NoteDatabase.getInstance(NoteDatabase.java:25)
61    at com.emirhalici.notetakingappnvvmexample.NoteRepository.&lt;init&gt;(NoteRepository.java:15)
62    at com.emirhalici.notetakingappnvvmexample.NoteViewModel.&lt;init&gt;(NoteViewModel.java:19)
63    at java.lang.reflect.Constructor.newInstance0(Native Method) 
64    at java.lang.reflect.Constructor.newInstance(Constructor.java:343) 
65    at androidx.lifecycle.ViewModelProvider$AndroidViewModelFactory.create(ViewModelProvider.java:267) 
66    at androidx.lifecycle.ViewModelProvider.get(ViewModelProvider.java:187) 
67    at androidx.lifecycle.ViewModelProvider.get(ViewModelProvider.java:150) 
68    at com.emirhalici.notetakingappnvvmexample.MainActivity.onCreate(MainActivity.java:26) 
69    at android.app.Activity.performCreate(Activity.java:8000) 
70    at android.app.Activity.performCreate(Activity.java:7984) 
71    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1309) 
72    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3422) 
73    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601) 
74    at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85) 
75    at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) 
76    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) 
77    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066) 
78    at android.os.Handler.dispatchMessage(Handler.java:106) 
79    at android.os.Looper.loop(Looper.java:223) 
80    at android.app.ActivityThread.main(ActivityThread.java:7656) 
81    at java.lang.reflect.Method.invoke(Native Method) 
82    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592) 
83    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947) 
84public class MainActivity extends AppCompatActivity {
85private NoteViewModel noteViewModel;
86
87@Override
88protected void onCreate(Bundle savedInstanceState) {
89    super.onCreate(savedInstanceState);
90    setContentView(R.layout.activity_main);
91
92    // these didn't work
93    //noteViewModel = new ViewModelProvider(this, ViewModelProvider.AndroidViewModelFactory.getInstance(this.getApplication())).get(NoteViewModel.class);
94    //noteViewModel = new ViewModelProvider(this).get(NoteViewModel.class);
95    //noteViewModel = ViewModelProviders.of(this).get(NoteViewModel.class);
96    // i tried this but this don't work either
97    noteViewModel = new ViewModelProvider(this,
98            ViewModelProvider.AndroidViewModelFactory.getInstance(this.getApplication())).get(NoteViewModel.class);
99    noteViewModel.getAllNotes().observe(this, new Observer&lt;List&lt;Note&gt;&gt;() {
100        @Override
101        public void onChanged(List&lt;Note&gt; notes) {
102            // update RecyclerView
103            Toast.makeText(MainActivity.this, &quot;onChanged&quot;, Toast.LENGTH_SHORT).show();
104        }
105    });
106} }
107@Entity(tableName = &quot;note_table&quot;)
108public class Note {
109
110@PrimaryKey(autoGenerate = true)
111private int id;
112
113private String title;
114private String description;
115private int priority;
116
117// getters
118public int getId() {
119    return id;
120}
121
122public String getTitle() {
123    return title;
124}
125
126public String getDescription() {
127    return description;
128}
129
130public int getPriority() {
131    return priority;
132}
133
134// id setter
135public void setId(int id) {
136    this.id = id;
137}
138
139// constructor
140public Note(String title, String description, int priority) {
141    this.title = title;
142    this.description = description;
143    this.priority = priority;
144}
145
146}
147@Dao
148public interface NoteDao {
149
150@Insert
151void insert(Note note);
152
153@Update
154void update(Note note);
155
156@Delete
157void delete(Note note);
158
159@Query(&quot;DELETE FROM note_table&quot;)
160void deleteAll();
161
162@Query(&quot;SELECT * FROM note_table ORDER BY priority DESC&quot;)
163LiveData&lt;List&lt;Note&gt;&gt; getAllNotes();
164
165}
166@Database(entities = Note.class, version = 1)
167public abstract class NoteDatabase extends RoomDatabase {
168
169private static NoteDatabase instance;
170
171public abstract NoteDao noteDao();
172
173public static synchronized NoteDatabase getInstance(Context context) {
174    if (instance == null) {
175        instance = Room.databaseBuilder(context.getApplicationContext(),
176                NoteDatabase.class, &quot;note_database&quot;)
177                .fallbackToDestructiveMigration()
178                .addCallback(roomCallback)
179                .build();
180    }
181    return instance;
182}
183
184private static RoomDatabase.Callback roomCallback = new RoomDatabase.Callback() {
185    @Override
186    public void onCreate(@NonNull SupportSQLiteDatabase db) {
187        super.onCreate(db);
188        new PopulateDbAsyncTask(instance).execute();
189    }
190};
191
192private static class PopulateDbAsyncTask extends AsyncTask&lt;Void, Void, Void&gt; {
193    private NoteDao noteDao;
194    private PopulateDbAsyncTask(NoteDatabase db) {
195        noteDao = db.noteDao();
196    }
197
198    @Override
199    protected Void doInBackground(Void... voids) {
200        noteDao.insert(new Note(&quot;Title 1&quot;,&quot;Description 1&quot;, 1));
201        noteDao.insert(new Note(&quot;Title 2&quot;,&quot;Description 2&quot;, 2));
202        noteDao.insert(new Note(&quot;Title 3&quot;,&quot;Description 3&quot;, 3));
203        noteDao.insert(new Note(&quot;Title 4&quot;,&quot;Description 4&quot;, 1));
204        noteDao.insert(new Note(&quot;Title 5&quot;,&quot;Description 5&quot;, 2));
205        noteDao.insert(new Note(&quot;Title 6&quot;,&quot;Description 6&quot;, 4));
206        return null;
207    }
208}
209}
210public class NoteRepository {
211private NoteDao noteDao;
212private LiveData&lt;List&lt;Note&gt;&gt; allNotes;
213
214public NoteRepository(Application application) {
215    NoteDatabase database = NoteDatabase.getInstance(application);
216    noteDao = database.noteDao();
217    allNotes = noteDao.getAllNotes();
218}
219
220public void insert(Note note) {
221    new InsertNoteAsyncTask(noteDao).execute(note);
222}
223
224public void update(Note note) {
225    new UpdateNoteAsyncTask(noteDao).execute(note);
226}
227
228public void delete(Note note) {
229    new DeleteNoteAsyncTask(noteDao).execute(note);
230}
231
232public void deleteAll() {
233    new DeleteAllNotesAsyncTask(noteDao).execute();
234}
235
236public LiveData&lt;List&lt;Note&gt;&gt; getAllNotes() {
237    return allNotes;
238}
239
240private static class InsertNoteAsyncTask extends AsyncTask&lt;Note, Void, Void&gt; {
241    private NoteDao noteDao;
242
243    private InsertNoteAsyncTask(NoteDao noteDao) {
244        this.noteDao = noteDao;
245    }
246
247    @Override
248    protected Void doInBackground(Note... notes) {
249        noteDao.insert(notes[0]);
250        return null;
251    }
252}
253
254private static class UpdateNoteAsyncTask extends AsyncTask&lt;Note, Void, Void&gt; {
255    private NoteDao noteDao;
256
257    private UpdateNoteAsyncTask(NoteDao noteDao) {
258        this.noteDao = noteDao;
259    }
260
261    @Override
262    protected Void doInBackground(Note... notes) {
263        noteDao.update(notes[0]);
264        return null;
265    }
266}
267
268private static class DeleteNoteAsyncTask extends AsyncTask&lt;Note, Void, Void&gt; {
269    private NoteDao noteDao;
270
271    private DeleteNoteAsyncTask(NoteDao noteDao) {
272        this.noteDao = noteDao;
273    }
274
275    @Override
276    protected Void doInBackground(Note... notes) {
277        noteDao.delete(notes[0]);
278        return null;
279    }
280}
281
282private static class DeleteAllNotesAsyncTask extends AsyncTask&lt;Note, Void, Void&gt; {
283    private NoteDao noteDao;
284
285    private DeleteAllNotesAsyncTask(NoteDao noteDao) {
286        this.noteDao = noteDao;
287    }
288
289    @Override
290    protected Void doInBackground(Note... voids) {
291        noteDao.deleteAll();
292        return null;
293    }
294}
295}
296public class NoteViewModel extends AndroidViewModel {
297private NoteRepository repository;
298private LiveData&lt;List&lt;Note&gt;&gt; allNotes;
299
300public NoteViewModel(@NonNull Application application) {
301    super(application);
302    repository = new NoteRepository(application);
303    allNotes = repository.getAllNotes();
304}
305
306public void insert(Note note) {
307    repository.insert(note);
308}
309
310public void update(Note note) {
311    repository.update(note);
312}
313
314public void delete(Note note) {
315    repository.delete(note);
316}
317
318public void deleteAllNotes() {
319    repository.deleteAll();
320}
321
322public LiveData&lt;List&lt;Note&gt;&gt; getAllNotes() {
323    return allNotes;
324}
325
326}
327

ANSWER

Answered 2021-May-09 at 07:58

Let me start off by saying CodeInFlow is a great source to learn from I've used him lots to help build my knowledge, Codelabs are also great and frequently updated by the Android dev team. If you are starting out I would recommend learning Kotlin over java, Kotlin is the future of android and recommend language by the Android Dev Team.

This is how you get a new or existing ViewModel.

1    Process: com.emirhalici.notetakingappnvvmexample, PID: 17577
2java.lang.RuntimeException: Unable to start activity ComponentInfo{com.emirhalici.notetakingappnvvmexample/com.emirhalici.notetakingappnvvmexample.MainActivity}: java.lang.RuntimeException: Cannot create an instance of class com.emirhalici.notetakingappnvvmexample.NoteViewModel
3    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3449)
4    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601)
5    at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
6    at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
7    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
8    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066)
9    at android.os.Handler.dispatchMessage(Handler.java:106)
10    at android.os.Looper.loop(Looper.java:223)
11    at android.app.ActivityThread.main(ActivityThread.java:7656)
12    at java.lang.reflect.Method.invoke(Native Method)
13    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
14    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
15 Caused by: java.lang.RuntimeException: Cannot create an instance of class com.emirhalici.notetakingappnvvmexample.NoteViewModel
16    at androidx.lifecycle.ViewModelProvider$AndroidViewModelFactory.create(ViewModelProvider.java:275)
17    at androidx.lifecycle.ViewModelProvider.get(ViewModelProvider.java:187)
18    at androidx.lifecycle.ViewModelProvider.get(ViewModelProvider.java:150)
19    at com.emirhalici.notetakingappnvvmexample.MainActivity.onCreate(MainActivity.java:26)
20    at android.app.Activity.performCreate(Activity.java:8000)
21    at android.app.Activity.performCreate(Activity.java:7984)
22    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1309)
23    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3422)
24    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601) 
25    at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85) 
26    at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) 
27    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) 
28    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066) 
29    at android.os.Handler.dispatchMessage(Handler.java:106) 
30    at android.os.Looper.loop(Looper.java:223) 
31    at android.app.ActivityThread.main(ActivityThread.java:7656) 
32    at java.lang.reflect.Method.invoke(Native Method) 
33    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592) 
34    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947) 
35 Caused by: java.lang.reflect.InvocationTargetException
36    at java.lang.reflect.Constructor.newInstance0(Native Method)
37    at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
38    at androidx.lifecycle.ViewModelProvider$AndroidViewModelFactory.create(ViewModelProvider.java:267)
39    at androidx.lifecycle.ViewModelProvider.get(ViewModelProvider.java:187) 
40    at androidx.lifecycle.ViewModelProvider.get(ViewModelProvider.java:150) 
41    at com.emirhalici.notetakingappnvvmexample.MainActivity.onCreate(MainActivity.java:26) 
42    at android.app.Activity.performCreate(Activity.java:8000) 
43    at android.app.Activity.performCreate(Activity.java:7984) 
44    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1309) 
45    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3422) 
46    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601) 
47    at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85) 
48    at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) 
49    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) 
50    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066) 
51    at android.os.Handler.dispatchMessage(Handler.java:106) 
52    at android.os.Looper.loop(Looper.java:223) 
53    at android.app.ActivityThread.main(ActivityThread.java:7656) 
54    at java.lang.reflect.Method.invoke(Native Method) 
55    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592) 
56    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947) 
57 Caused by: java.lang.RuntimeException: cannot find implementation for com.emirhalici.notetakingappnvvmexample.NoteDatabase. NoteDatabase_Impl does not exist
58    at androidx.room.Room.getGeneratedImplementation(Room.java:97)
59    at androidx.room.RoomDatabase$Builder.build(RoomDatabase.java:1358)
60    at com.emirhalici.notetakingappnvvmexample.NoteDatabase.getInstance(NoteDatabase.java:25)
61    at com.emirhalici.notetakingappnvvmexample.NoteRepository.&lt;init&gt;(NoteRepository.java:15)
62    at com.emirhalici.notetakingappnvvmexample.NoteViewModel.&lt;init&gt;(NoteViewModel.java:19)
63    at java.lang.reflect.Constructor.newInstance0(Native Method) 
64    at java.lang.reflect.Constructor.newInstance(Constructor.java:343) 
65    at androidx.lifecycle.ViewModelProvider$AndroidViewModelFactory.create(ViewModelProvider.java:267) 
66    at androidx.lifecycle.ViewModelProvider.get(ViewModelProvider.java:187) 
67    at androidx.lifecycle.ViewModelProvider.get(ViewModelProvider.java:150) 
68    at com.emirhalici.notetakingappnvvmexample.MainActivity.onCreate(MainActivity.java:26) 
69    at android.app.Activity.performCreate(Activity.java:8000) 
70    at android.app.Activity.performCreate(Activity.java:7984) 
71    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1309) 
72    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3422) 
73    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601) 
74    at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85) 
75    at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) 
76    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) 
77    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066) 
78    at android.os.Handler.dispatchMessage(Handler.java:106) 
79    at android.os.Looper.loop(Looper.java:223) 
80    at android.app.ActivityThread.main(ActivityThread.java:7656) 
81    at java.lang.reflect.Method.invoke(Native Method) 
82    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592) 
83    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947) 
84public class MainActivity extends AppCompatActivity {
85private NoteViewModel noteViewModel;
86
87@Override
88protected void onCreate(Bundle savedInstanceState) {
89    super.onCreate(savedInstanceState);
90    setContentView(R.layout.activity_main);
91
92    // these didn't work
93    //noteViewModel = new ViewModelProvider(this, ViewModelProvider.AndroidViewModelFactory.getInstance(this.getApplication())).get(NoteViewModel.class);
94    //noteViewModel = new ViewModelProvider(this).get(NoteViewModel.class);
95    //noteViewModel = ViewModelProviders.of(this).get(NoteViewModel.class);
96    // i tried this but this don't work either
97    noteViewModel = new ViewModelProvider(this,
98            ViewModelProvider.AndroidViewModelFactory.getInstance(this.getApplication())).get(NoteViewModel.class);
99    noteViewModel.getAllNotes().observe(this, new Observer&lt;List&lt;Note&gt;&gt;() {
100        @Override
101        public void onChanged(List&lt;Note&gt; notes) {
102            // update RecyclerView
103            Toast.makeText(MainActivity.this, &quot;onChanged&quot;, Toast.LENGTH_SHORT).show();
104        }
105    });
106} }
107@Entity(tableName = &quot;note_table&quot;)
108public class Note {
109
110@PrimaryKey(autoGenerate = true)
111private int id;
112
113private String title;
114private String description;
115private int priority;
116
117// getters
118public int getId() {
119    return id;
120}
121
122public String getTitle() {
123    return title;
124}
125
126public String getDescription() {
127    return description;
128}
129
130public int getPriority() {
131    return priority;
132}
133
134// id setter
135public void setId(int id) {
136    this.id = id;
137}
138
139// constructor
140public Note(String title, String description, int priority) {
141    this.title = title;
142    this.description = description;
143    this.priority = priority;
144}
145
146}
147@Dao
148public interface NoteDao {
149
150@Insert
151void insert(Note note);
152
153@Update
154void update(Note note);
155
156@Delete
157void delete(Note note);
158
159@Query(&quot;DELETE FROM note_table&quot;)
160void deleteAll();
161
162@Query(&quot;SELECT * FROM note_table ORDER BY priority DESC&quot;)
163LiveData&lt;List&lt;Note&gt;&gt; getAllNotes();
164
165}
166@Database(entities = Note.class, version = 1)
167public abstract class NoteDatabase extends RoomDatabase {
168
169private static NoteDatabase instance;
170
171public abstract NoteDao noteDao();
172
173public static synchronized NoteDatabase getInstance(Context context) {
174    if (instance == null) {
175        instance = Room.databaseBuilder(context.getApplicationContext(),
176                NoteDatabase.class, &quot;note_database&quot;)
177                .fallbackToDestructiveMigration()
178                .addCallback(roomCallback)
179                .build();
180    }
181    return instance;
182}
183
184private static RoomDatabase.Callback roomCallback = new RoomDatabase.Callback() {
185    @Override
186    public void onCreate(@NonNull SupportSQLiteDatabase db) {
187        super.onCreate(db);
188        new PopulateDbAsyncTask(instance).execute();
189    }
190};
191
192private static class PopulateDbAsyncTask extends AsyncTask&lt;Void, Void, Void&gt; {
193    private NoteDao noteDao;
194    private PopulateDbAsyncTask(NoteDatabase db) {
195        noteDao = db.noteDao();
196    }
197
198    @Override
199    protected Void doInBackground(Void... voids) {
200        noteDao.insert(new Note(&quot;Title 1&quot;,&quot;Description 1&quot;, 1));
201        noteDao.insert(new Note(&quot;Title 2&quot;,&quot;Description 2&quot;, 2));
202        noteDao.insert(new Note(&quot;Title 3&quot;,&quot;Description 3&quot;, 3));
203        noteDao.insert(new Note(&quot;Title 4&quot;,&quot;Description 4&quot;, 1));
204        noteDao.insert(new Note(&quot;Title 5&quot;,&quot;Description 5&quot;, 2));
205        noteDao.insert(new Note(&quot;Title 6&quot;,&quot;Description 6&quot;, 4));
206        return null;
207    }
208}
209}
210public class NoteRepository {
211private NoteDao noteDao;
212private LiveData&lt;List&lt;Note&gt;&gt; allNotes;
213
214public NoteRepository(Application application) {
215    NoteDatabase database = NoteDatabase.getInstance(application);
216    noteDao = database.noteDao();
217    allNotes = noteDao.getAllNotes();
218}
219
220public void insert(Note note) {
221    new InsertNoteAsyncTask(noteDao).execute(note);
222}
223
224public void update(Note note) {
225    new UpdateNoteAsyncTask(noteDao).execute(note);
226}
227
228public void delete(Note note) {
229    new DeleteNoteAsyncTask(noteDao).execute(note);
230}
231
232public void deleteAll() {
233    new DeleteAllNotesAsyncTask(noteDao).execute();
234}
235
236public LiveData&lt;List&lt;Note&gt;&gt; getAllNotes() {
237    return allNotes;
238}
239
240private static class InsertNoteAsyncTask extends AsyncTask&lt;Note, Void, Void&gt; {
241    private NoteDao noteDao;
242
243    private InsertNoteAsyncTask(NoteDao noteDao) {
244        this.noteDao = noteDao;
245    }
246
247    @Override
248    protected Void doInBackground(Note... notes) {
249        noteDao.insert(notes[0]);
250        return null;
251    }
252}
253
254private static class UpdateNoteAsyncTask extends AsyncTask&lt;Note, Void, Void&gt; {
255    private NoteDao noteDao;
256
257    private UpdateNoteAsyncTask(NoteDao noteDao) {
258        this.noteDao = noteDao;
259    }
260
261    @Override
262    protected Void doInBackground(Note... notes) {
263        noteDao.update(notes[0]);
264        return null;
265    }
266}
267
268private static class DeleteNoteAsyncTask extends AsyncTask&lt;Note, Void, Void&gt; {
269    private NoteDao noteDao;
270
271    private DeleteNoteAsyncTask(NoteDao noteDao) {
272        this.noteDao = noteDao;
273    }
274
275    @Override
276    protected Void doInBackground(Note... notes) {
277        noteDao.delete(notes[0]);
278        return null;
279    }
280}
281
282private static class DeleteAllNotesAsyncTask extends AsyncTask&lt;Note, Void, Void&gt; {
283    private NoteDao noteDao;
284
285    private DeleteAllNotesAsyncTask(NoteDao noteDao) {
286        this.noteDao = noteDao;
287    }
288
289    @Override
290    protected Void doInBackground(Note... voids) {
291        noteDao.deleteAll();
292        return null;
293    }
294}
295}
296public class NoteViewModel extends AndroidViewModel {
297private NoteRepository repository;
298private LiveData&lt;List&lt;Note&gt;&gt; allNotes;
299
300public NoteViewModel(@NonNull Application application) {
301    super(application);
302    repository = new NoteRepository(application);
303    allNotes = repository.getAllNotes();
304}
305
306public void insert(Note note) {
307    repository.insert(note);
308}
309
310public void update(Note note) {
311    repository.update(note);
312}
313
314public void delete(Note note) {
315    repository.delete(note);
316}
317
318public void deleteAllNotes() {
319    repository.deleteAll();
320}
321
322public LiveData&lt;List&lt;Note&gt;&gt; getAllNotes() {
323    return allNotes;
324}
325
326}
327NoteViewModel viewModel = new ViewModelProvider(this).get(NoteViewModel.class);
328

Using a custom ViewModel Factory is not necessary for this project. You would only want to use custom ViewModel Factory if you are passing an argument into the ViewModel constructor.

Source https://stackoverflow.com/questions/67213223

QUESTION

Android MVVM: how to avoid multiple livedata triggers when data from network did not change

Asked 2021-May-03 at 14:33

I have this basic Android Architecture Component use-case where I observe a live-data and update UI.

1 myLiveData.observe(viewLifecycleOwner, Observer {
2     // update UI
3 })
4
5 // will trigger a network call and update the repository (Room DB)
6 myViewModel.refreshDataFromRepository()
7

With the observe call, I get the trigger and I update the UI, which is fine. However, I also need to update the DB if the backend data has changed, so I trigger a network refresh and that updates the DB and triggers the observer once again. So, I am getting data twice.

I can change conflict strategy to ignore to avoid but I need to set it to "replace" as the data may change:

1 myLiveData.observe(viewLifecycleOwner, Observer {
2     // update UI
3 })
4
5 // will trigger a network call and update the repository (Room DB)
6 myViewModel.refreshDataFromRepository()
7@Query(&quot;SELECT * FROM my_table ORDER BY timestamp DESC&quot;)
8fun getMyEntities(): LiveData&lt;List&lt;MyEntity&gt;&gt;
9
10@Insert(onConflict = OnConflictStrategy.REPLACE)
11suspend fun add(myEntity: MyEntity)
12

Other option is to compare the network response with DB contents and avoid re-writing identical data but would be expensive.

Is there any way, database access can be made intelligent to avoid trigger if data has not changed?

ANSWER

Answered 2021-May-03 at 14:33

You could use distinctUntilChanged, it has been added to Transformations:

1 myLiveData.observe(viewLifecycleOwner, Observer {
2     // update UI
3 })
4
5 // will trigger a network call and update the repository (Room DB)
6 myViewModel.refreshDataFromRepository()
7@Query(&quot;SELECT * FROM my_table ORDER BY timestamp DESC&quot;)
8fun getMyEntities(): LiveData&lt;List&lt;MyEntity&gt;&gt;
9
10@Insert(onConflict = OnConflictStrategy.REPLACE)
11suspend fun add(myEntity: MyEntity)
12myLiveData.distinctUntilChanged().observe(viewLifecycleOwner) {
13     // update UI
14 }
15

Source https://stackoverflow.com/questions/67344321

QUESTION

Can I add Observer inside Observer? I actually tried but inner observers not working properly. Sometimes one of them work, sometimes no one work

Asked 2021-Apr-09 at 10:27

I used Android Architecture Components (ViewModel, LiveData) and used Room to fetch data from Local Sqlite Database using Repository. Outermost observer just fine, problem is only with inner observers.

See the Code:

1    @Override
2    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
3        super.onViewCreated(view, savedInstanceState);
4        BranchDetailsViewModel branchDetailsViewModel = new BranchDetailsViewModel(application);
5
6        Observer&lt;Bank&gt; bankObserver = new Observer&lt;Bank&gt;() {
7            @Override
8            public void onChanged(Bank bank) {
9                if(bank!= null)
10                    binding.tvBank.setText(bank.getBank());
11            }
12        };
13
14
15        branchDetailsViewModel.getBranchById(branchIid).observe(this, new Observer&lt;Branch&gt;() {
16            @Override
17            public void onChanged(Branch branch) {
18
19                branchDetailsViewModel.getBankById(branch.getBankId()).observe(getViewLifecycleOwner(), bankObserver);
20
21                branchDetailsViewModel.getCityById(branch.getCityId()).observe(requireActivity(), new Observer&lt;City&gt;() {
22                    @Override
23                    public void onChanged(City city) {
24                        if(city != null)
25                        binding.tvCity.setText(city.getCity() + &quot; cty&quot;);
26                    }
27                });
28
29                branchDetailsViewModel.getDistrictById(branch.getDistrictId()).observe(requireActivity(), new Observer&lt;District&gt;() {
30                    @Override
31                    public void onChanged(District district) {
32                        if(district != null)
33                        binding.tvDistrict.setText(district.getDistrict());
34                    }
35                });
36
37                branchDetailsViewModel.getStateById(branch.getStateId()).observe(requireActivity(), new Observer&lt;State&gt;() {
38                    @Override
39                    public void onChanged(State state) {
40                        if(state!= null)
41                        binding.tvState.setText(state.getState());
42                    }
43                });
44            }
45        });
46    }
47

I tried it both using named and anonymous Observers. I can't understand what is the problem here.

Sometimes it thorow NullPointerExceptions. Sometimes Failed to change locale.

1    @Override
2    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
3        super.onViewCreated(view, savedInstanceState);
4        BranchDetailsViewModel branchDetailsViewModel = new BranchDetailsViewModel(application);
5
6        Observer&lt;Bank&gt; bankObserver = new Observer&lt;Bank&gt;() {
7            @Override
8            public void onChanged(Bank bank) {
9                if(bank!= null)
10                    binding.tvBank.setText(bank.getBank());
11            }
12        };
13
14
15        branchDetailsViewModel.getBranchById(branchIid).observe(this, new Observer&lt;Branch&gt;() {
16            @Override
17            public void onChanged(Branch branch) {
18
19                branchDetailsViewModel.getBankById(branch.getBankId()).observe(getViewLifecycleOwner(), bankObserver);
20
21                branchDetailsViewModel.getCityById(branch.getCityId()).observe(requireActivity(), new Observer&lt;City&gt;() {
22                    @Override
23                    public void onChanged(City city) {
24                        if(city != null)
25                        binding.tvCity.setText(city.getCity() + &quot; cty&quot;);
26                    }
27                });
28
29                branchDetailsViewModel.getDistrictById(branch.getDistrictId()).observe(requireActivity(), new Observer&lt;District&gt;() {
30                    @Override
31                    public void onChanged(District district) {
32                        if(district != null)
33                        binding.tvDistrict.setText(district.getDistrict());
34                    }
35                });
36
37                branchDetailsViewModel.getStateById(branch.getStateId()).observe(requireActivity(), new Observer&lt;State&gt;() {
38                    @Override
39                    public void onChanged(State state) {
40                        if(state!= null)
41                        binding.tvState.setText(state.getState());
42                    }
43                });
44            }
45        });
46    }
4704-09 15:48:45.182 2096-2113/com.appsbharti.bharatbankdetails E/SQLiteDatabase: Failed to open database '/data/data/com.appsbharti.bharatbankdetails/databases/bank_details.db'.
48    android.database.sqlite.SQLiteException: Failed to change locale for db '/data/data/com.appsbharti.bharatbankdetails/databases/bank_details.db' to 'en_IN'.
49        at android.database.sqlite.SQLiteConnection.setLocaleFromConfiguration(SQLiteConnection.java:386)
50        at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:218)
51        at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:193)
52        at android.database.sqlite.SQLiteConnectionPool.openConnectionLocked(SQLiteConnectionPool.java:463)
53        at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:185)
54        at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:177)
55        at android.database.sqlite.SQLiteDatabase.openInner(SQLiteDatabase.java:804)
56        at android.database.sqlite.SQLiteDatabase.open(SQLiteDatabase.java:789)
57        at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:694)
58        at android.app.ContextImpl.openOrCreateDatabase(ContextImpl.java:804)
59        at android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:221)
60        at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:224)
61        at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:164)
62        at androidx.sqlite.db.framework.FrameworkSQLiteOpenHelper$OpenHelper.getWritableSupportDatabase(FrameworkSQLiteOpenHelper.java:92)
63        at androidx.sqlite.db.framework.FrameworkSQLiteOpenHelper.getWritableDatabase(FrameworkSQLiteOpenHelper.java:53)
64        at androidx.room.SQLiteCopyOpenHelper.getWritableDatabase(SQLiteCopyOpenHelper.java:90)
65        at androidx.room.RoomDatabase.inTransaction(RoomDatabase.java:476)
66        at androidx.room.RoomDatabase.assertNotSuspendingTransaction(RoomDatabase.java:281)
67        at com.appsbharti.bharatbankdetails.Daos.HistoryDao_Impl.insert(HistoryDao_Impl.java:45)
68        at com.appsbharti.bharatbankdetails.Repositories.HistoryRepository$1.run(HistoryRepository.java:37)
69        at androidx.room.TransactionExecutor$1.run(TransactionExecutor.java:45)
70        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
71        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
72        at java.lang.Thread.run(Thread.java:856)
73     Caused by: android.database.sqlite.SQLiteDiskIOException: disk I/O error (code 1802)
74        at android.database.sqlite.SQLiteConnection.nativeExecute(Native Method)
75        at android.database.sqlite.SQLiteConnection.execute(SQLiteConnection.java:548)
76        at android.database.sqlite.SQLiteConnection.setLocaleFromConfiguration(SQLiteConnection.java:364)
77        at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:218) 
78        at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:193) 
79        at android.database.sqlite.SQLiteConnectionPool.openConnectionLocked(SQLiteConnectionPool.java:463) 
80        at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:185) 
81        at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:177) 
82        at android.database.sqlite.SQLiteDatabase.openInner(SQLiteDatabase.java:804) 
83        at android.database.sqlite.SQLiteDatabase.open(SQLiteDatabase.java:789) 
84        at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:694) 
85        at android.app.ContextImpl.openOrCreateDatabase(ContextImpl.java:804) 
86        at android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:221) 
87        at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:224) 
88        at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:164) 
89        at androidx.sqlite.db.framework.FrameworkSQLiteOpenHelper$OpenHelper.getWritableSupportDatabase(FrameworkSQLiteOpenHelper.java:92) 
90        at androidx.sqlite.db.framework.FrameworkSQLiteOpenHelper.getWritableDatabase(FrameworkSQLiteOpenHelper.java:53) 
91        at androidx.room.SQLiteCopyOpenHelper.getWritableDatabase(SQLiteCopyOpenHelper.java:90) 
92        at androidx.room.RoomDatabase.inTransaction(RoomDatabase.java:476) 
93        at androidx.room.RoomDatabase.assertNotSuspendingTransaction(RoomDatabase.java:281) 
94        at com.appsbharti.bharatbankdetails.Daos.HistoryDao_Impl.insert(HistoryDao_Impl.java:45) 
95        at com.appsbharti.bharatbankdetails.Repositories.HistoryRepository$1.run(HistoryRepository.java:37) 
96        at androidx.room.TransactionExecutor$1.run(TransactionExecutor.java:45) 
97        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076) 
98        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569) 
99        at java.lang.Thread.run(Thread.java:856) 
100

One more issue is that I am unsure which one I should use in Fragment as Observer's owner, requireActivity() or getActivity()(I get warning that this could return null, so I haven't used it) or getViewLifecycleOwner() (to get fragment's life cycle owner object).

ANSWER

Answered 2021-Apr-01 at 08:57

If you are inside a Fragment, you cannot pass this to observe, you should be passing viewlifecycleOwner. In your case you are setting an observe to get the value of branch from room, and then depending on the branch, your other observers are getting called.

This means that your inside observers will observe after your branch observer has been invoked.

When you bind your observers to the lifecycle of the fragment, the observers work in accordance with the lifecycle of the fragment itself.

Binding it with lifecycleowner should work, mainly because this does not work in case of fragment.

Source https://stackoverflow.com/questions/66864329

QUESTION

Why I am facing threading issues despite using room database TransactionExecutor?

Asked 2021-Apr-07 at 13:14

I have 2 fragments. One is showing Branch Details, other is showing showing branches viewed in history. I want to add entry whenver user see branch details.

I am following Android Architecture principles and using Room+LiveData+Repository+Viewmodel.

Here is BranchDetailsFragment:

1public class BranchDetailsFragment extends Fragment implements View.OnClickListener {
2
3    private final Application application;
4    private final int branchIid;
5
6    private FragBranchDetailsBinding binding;//view-binding
7
8    public BranchDetailsFragment(Application application, int branchIid) {
9        //saving branchId
10    }
11
12    @Nullable
13    @Override
14    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
15        //normal stuff
16    }
17
18    @Override
19    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
20        super.onViewCreated(view, savedInstanceState);
21        BranchDetailsViewModel branchDetailsViewModel = new BranchDetailsViewModel(application);
22        
23        //inserting entry in history table
24        HistoryViewModel historyViewModel = new HistoryViewModel(application);
25        History history = new History();
26        history.setBranchId(branchIid);
27        historyViewModel.insert(history);
28        
29        //fetching data from branches table
30        branchDetailsViewModel.getBranchCustomizedById(branchIid).observe(getViewLifecycleOwner(), new Observer&lt;BranchCustomized&gt;() {
31            @Override
32            public void onChanged(BranchCustomized branchCustomized) {
33                //get branch details and show them
34            }
35        });
36    }
37}
38

Here is the Branch POJO Room Entity:

1public class BranchDetailsFragment extends Fragment implements View.OnClickListener {
2
3    private final Application application;
4    private final int branchIid;
5
6    private FragBranchDetailsBinding binding;//view-binding
7
8    public BranchDetailsFragment(Application application, int branchIid) {
9        //saving branchId
10    }
11
12    @Nullable
13    @Override
14    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
15        //normal stuff
16    }
17
18    @Override
19    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
20        super.onViewCreated(view, savedInstanceState);
21        BranchDetailsViewModel branchDetailsViewModel = new BranchDetailsViewModel(application);
22        
23        //inserting entry in history table
24        HistoryViewModel historyViewModel = new HistoryViewModel(application);
25        History history = new History();
26        history.setBranchId(branchIid);
27        historyViewModel.insert(history);
28        
29        //fetching data from branches table
30        branchDetailsViewModel.getBranchCustomizedById(branchIid).observe(getViewLifecycleOwner(), new Observer&lt;BranchCustomized&gt;() {
31            @Override
32            public void onChanged(BranchCustomized branchCustomized) {
33                //get branch details and show them
34            }
35        });
36    }
37}
38@Entity(tableName = &quot;branches&quot;)
39public class Branch {
40    @PrimaryKey(autoGenerate = true)
41    @ColumnInfo(name = &quot;_id&quot;)
42    private int id;
43
44    @ColumnInfo(name = &quot;bank_id&quot;)
45    private int bankId;
46    
47    public int getId() {
48        return id;
49    }
50
51    public void setId(int id) {
52        this.id = id;
53    }
54
55    public int getBankId() {
56        return bankId;
57    }
58
59    public void setBankId(int bankId) {
60        this.bankId = bankId;
61    }
62
63}
64

Here is History POJO Room Entity:

1public class BranchDetailsFragment extends Fragment implements View.OnClickListener {
2
3    private final Application application;
4    private final int branchIid;
5
6    private FragBranchDetailsBinding binding;//view-binding
7
8    public BranchDetailsFragment(Application application, int branchIid) {
9        //saving branchId
10    }
11
12    @Nullable
13    @Override
14    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
15        //normal stuff
16    }
17
18    @Override
19    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
20        super.onViewCreated(view, savedInstanceState);
21        BranchDetailsViewModel branchDetailsViewModel = new BranchDetailsViewModel(application);
22        
23        //inserting entry in history table
24        HistoryViewModel historyViewModel = new HistoryViewModel(application);
25        History history = new History();
26        history.setBranchId(branchIid);
27        historyViewModel.insert(history);
28        
29        //fetching data from branches table
30        branchDetailsViewModel.getBranchCustomizedById(branchIid).observe(getViewLifecycleOwner(), new Observer&lt;BranchCustomized&gt;() {
31            @Override
32            public void onChanged(BranchCustomized branchCustomized) {
33                //get branch details and show them
34            }
35        });
36    }
37}
38@Entity(tableName = &quot;branches&quot;)
39public class Branch {
40    @PrimaryKey(autoGenerate = true)
41    @ColumnInfo(name = &quot;_id&quot;)
42    private int id;
43
44    @ColumnInfo(name = &quot;bank_id&quot;)
45    private int bankId;
46    
47    public int getId() {
48        return id;
49    }
50
51    public void setId(int id) {
52        this.id = id;
53    }
54
55    public int getBankId() {
56        return bankId;
57    }
58
59    public void setBankId(int bankId) {
60        this.bankId = bankId;
61    }
62
63}
64@Entity(tableName = &quot;history&quot;, foreignKeys = @ForeignKey(entity = Branch.class, parentColumns = &quot;_id&quot;, childColumns = &quot;branch_id&quot;))
65public class History {
66    @PrimaryKey(autoGenerate = true)
67    @ColumnInfo(name = &quot;_id&quot;)
68    private int id;
69
70    @ColumnInfo(name = &quot;branch_id&quot;)
71    private int branchId;
72
73    public int getId() {
74        return id;
75    }
76
77    public void setId(int id) {
78        this.id = id;
79    }
80
81    public int getBranchId() {
82        return branchId;
83    }
84
85    public void setBranchId(int branchId) {
86        this.branchId = branchId;
87    }
88}
89

Here is historyViewModel

1public class BranchDetailsFragment extends Fragment implements View.OnClickListener {
2
3    private final Application application;
4    private final int branchIid;
5
6    private FragBranchDetailsBinding binding;//view-binding
7
8    public BranchDetailsFragment(Application application, int branchIid) {
9        //saving branchId
10    }
11
12    @Nullable
13    @Override
14    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
15        //normal stuff
16    }
17
18    @Override
19    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
20        super.onViewCreated(view, savedInstanceState);
21        BranchDetailsViewModel branchDetailsViewModel = new BranchDetailsViewModel(application);
22        
23        //inserting entry in history table
24        HistoryViewModel historyViewModel = new HistoryViewModel(application);
25        History history = new History();
26        history.setBranchId(branchIid);
27        historyViewModel.insert(history);
28        
29        //fetching data from branches table
30        branchDetailsViewModel.getBranchCustomizedById(branchIid).observe(getViewLifecycleOwner(), new Observer&lt;BranchCustomized&gt;() {
31            @Override
32            public void onChanged(BranchCustomized branchCustomized) {
33                //get branch details and show them
34            }
35        });
36    }
37}
38@Entity(tableName = &quot;branches&quot;)
39public class Branch {
40    @PrimaryKey(autoGenerate = true)
41    @ColumnInfo(name = &quot;_id&quot;)
42    private int id;
43
44    @ColumnInfo(name = &quot;bank_id&quot;)
45    private int bankId;
46    
47    public int getId() {
48        return id;
49    }
50
51    public void setId(int id) {
52        this.id = id;
53    }
54
55    public int getBankId() {
56        return bankId;
57    }
58
59    public void setBankId(int bankId) {
60        this.bankId = bankId;
61    }
62
63}
64@Entity(tableName = &quot;history&quot;, foreignKeys = @ForeignKey(entity = Branch.class, parentColumns = &quot;_id&quot;, childColumns = &quot;branch_id&quot;))
65public class History {
66    @PrimaryKey(autoGenerate = true)
67    @ColumnInfo(name = &quot;_id&quot;)
68    private int id;
69
70    @ColumnInfo(name = &quot;branch_id&quot;)
71    private int branchId;
72
73    public int getId() {
74        return id;
75    }
76
77    public void setId(int id) {
78        this.id = id;
79    }
80
81    public int getBranchId() {
82        return branchId;
83    }
84
85    public void setBranchId(int branchId) {
86        this.branchId = branchId;
87    }
88}
89public class HistoryViewModel extends AndroidViewModel {
90    final HistoryRepository repository;
91
92    public HistoryViewModel(Application application) {
93        super(application);
94        repository = new HistoryRepository(application);
95    }
96
97    public LiveData&lt;List&lt;HistoryCustomized&gt;&gt; getAll(){
98        return repository.getAll();
99    }
100
101    public LiveData&lt;List&lt;HistoryCustomized&gt;&gt;  searchHistoryByBankOrBranch(String token){
102        return repository.searchHistoryByBankOrBranch(token);
103    }
104
105    public void insert(History history){
106        repository.insert(history);
107    }
108}
109

Here is HistoryRepository

1public class BranchDetailsFragment extends Fragment implements View.OnClickListener {
2
3    private final Application application;
4    private final int branchIid;
5
6    private FragBranchDetailsBinding binding;//view-binding
7
8    public BranchDetailsFragment(Application application, int branchIid) {
9        //saving branchId
10    }
11
12    @Nullable
13    @Override
14    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
15        //normal stuff
16    }
17
18    @Override
19    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
20        super.onViewCreated(view, savedInstanceState);
21        BranchDetailsViewModel branchDetailsViewModel = new BranchDetailsViewModel(application);
22        
23        //inserting entry in history table
24        HistoryViewModel historyViewModel = new HistoryViewModel(application);
25        History history = new History();
26        history.setBranchId(branchIid);
27        historyViewModel.insert(history);
28        
29        //fetching data from branches table
30        branchDetailsViewModel.getBranchCustomizedById(branchIid).observe(getViewLifecycleOwner(), new Observer&lt;BranchCustomized&gt;() {
31            @Override
32            public void onChanged(BranchCustomized branchCustomized) {
33                //get branch details and show them
34            }
35        });
36    }
37}
38@Entity(tableName = &quot;branches&quot;)
39public class Branch {
40    @PrimaryKey(autoGenerate = true)
41    @ColumnInfo(name = &quot;_id&quot;)
42    private int id;
43
44    @ColumnInfo(name = &quot;bank_id&quot;)
45    private int bankId;
46    
47    public int getId() {
48        return id;
49    }
50
51    public void setId(int id) {
52        this.id = id;
53    }
54
55    public int getBankId() {
56        return bankId;
57    }
58
59    public void setBankId(int bankId) {
60        this.bankId = bankId;
61    }
62
63}
64@Entity(tableName = &quot;history&quot;, foreignKeys = @ForeignKey(entity = Branch.class, parentColumns = &quot;_id&quot;, childColumns = &quot;branch_id&quot;))
65public class History {
66    @PrimaryKey(autoGenerate = true)
67    @ColumnInfo(name = &quot;_id&quot;)
68    private int id;
69
70    @ColumnInfo(name = &quot;branch_id&quot;)
71    private int branchId;
72
73    public int getId() {
74        return id;
75    }
76
77    public void setId(int id) {
78        this.id = id;
79    }
80
81    public int getBranchId() {
82        return branchId;
83    }
84
85    public void setBranchId(int branchId) {
86        this.branchId = branchId;
87    }
88}
89public class HistoryViewModel extends AndroidViewModel {
90    final HistoryRepository repository;
91
92    public HistoryViewModel(Application application) {
93        super(application);
94        repository = new HistoryRepository(application);
95    }
96
97    public LiveData&lt;List&lt;HistoryCustomized&gt;&gt; getAll(){
98        return repository.getAll();
99    }
100
101    public LiveData&lt;List&lt;HistoryCustomized&gt;&gt;  searchHistoryByBankOrBranch(String token){
102        return repository.searchHistoryByBankOrBranch(token);
103    }
104
105    public void insert(History history){
106        repository.insert(history);
107    }
108}
109public class HistoryRepository {
110    private final HistoryDao dao;
111    AppDatabase db;
112
113
114    public HistoryRepository(Application application) {
115        db = AppDatabase.getInstance(application);
116        dao = db.getHistoryDao();
117    }
118
119    public LiveData&lt;List&lt;HistoryCustomized&gt;&gt; getAll() {
120        return dao.getAll();
121    }
122
123    public LiveData&lt;List&lt;HistoryCustomized&gt;&gt; searchHistoryByBankOrBranch(String token) {
124        return dao.searchHistoryByBankOrBranch(token);
125    }
126
127    public void insert(History history){
128        try {
129            db.getTransactionExecutor().execute(new Runnable() {
130                @Override
131                public void run() {
132                    dao.insert(history);
133                }
134            });
135        }catch (NullPointerException e){
136            e.printStackTrace();
137        }
138    }
139}
140

Here is HistoryDao

1public class BranchDetailsFragment extends Fragment implements View.OnClickListener {
2
3    private final Application application;
4    private final int branchIid;
5
6    private FragBranchDetailsBinding binding;//view-binding
7
8    public BranchDetailsFragment(Application application, int branchIid) {
9        //saving branchId
10    }
11
12    @Nullable
13    @Override
14    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
15        //normal stuff
16    }
17
18    @Override
19    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
20        super.onViewCreated(view, savedInstanceState);
21        BranchDetailsViewModel branchDetailsViewModel = new BranchDetailsViewModel(application);
22        
23        //inserting entry in history table
24        HistoryViewModel historyViewModel = new HistoryViewModel(application);
25        History history = new History();
26        history.setBranchId(branchIid);
27        historyViewModel.insert(history);
28        
29        //fetching data from branches table
30        branchDetailsViewModel.getBranchCustomizedById(branchIid).observe(getViewLifecycleOwner(), new Observer&lt;BranchCustomized&gt;() {
31            @Override
32            public void onChanged(BranchCustomized branchCustomized) {
33                //get branch details and show them
34            }
35        });
36    }
37}
38@Entity(tableName = &quot;branches&quot;)
39public class Branch {
40    @PrimaryKey(autoGenerate = true)
41    @ColumnInfo(name = &quot;_id&quot;)
42    private int id;
43
44    @ColumnInfo(name = &quot;bank_id&quot;)
45    private int bankId;
46    
47    public int getId() {
48        return id;
49    }
50
51    public void setId(int id) {
52        this.id = id;
53    }
54
55    public int getBankId() {
56        return bankId;
57    }
58
59    public void setBankId(int bankId) {
60        this.bankId = bankId;
61    }
62
63}
64@Entity(tableName = &quot;history&quot;, foreignKeys = @ForeignKey(entity = Branch.class, parentColumns = &quot;_id&quot;, childColumns = &quot;branch_id&quot;))
65public class History {
66    @PrimaryKey(autoGenerate = true)
67    @ColumnInfo(name = &quot;_id&quot;)
68    private int id;
69
70    @ColumnInfo(name = &quot;branch_id&quot;)
71    private int branchId;
72
73    public int getId() {
74        return id;
75    }
76
77    public void setId(int id) {
78        this.id = id;
79    }
80
81    public int getBranchId() {
82        return branchId;
83    }
84
85    public void setBranchId(int branchId) {
86        this.branchId = branchId;
87    }
88}
89public class HistoryViewModel extends AndroidViewModel {
90    final HistoryRepository repository;
91
92    public HistoryViewModel(Application application) {
93        super(application);
94        repository = new HistoryRepository(application);
95    }
96
97    public LiveData&lt;List&lt;HistoryCustomized&gt;&gt; getAll(){
98        return repository.getAll();
99    }
100
101    public LiveData&lt;List&lt;HistoryCustomized&gt;&gt;  searchHistoryByBankOrBranch(String token){
102        return repository.searchHistoryByBankOrBranch(token);
103    }
104
105    public void insert(History history){
106        repository.insert(history);
107    }
108}
109public class HistoryRepository {
110    private final HistoryDao dao;
111    AppDatabase db;
112
113
114    public HistoryRepository(Application application) {
115        db = AppDatabase.getInstance(application);
116        dao = db.getHistoryDao();
117    }
118
119    public LiveData&lt;List&lt;HistoryCustomized&gt;&gt; getAll() {
120        return dao.getAll();
121    }
122
123    public LiveData&lt;List&lt;HistoryCustomized&gt;&gt; searchHistoryByBankOrBranch(String token) {
124        return dao.searchHistoryByBankOrBranch(token);
125    }
126
127    public void insert(History history){
128        try {
129            db.getTransactionExecutor().execute(new Runnable() {
130                @Override
131                public void run() {
132                    dao.insert(history);
133                }
134            });
135        }catch (NullPointerException e){
136            e.printStackTrace();
137        }
138    }
139}
140@Dao
141public interface HistoryDao {
142    @Query(&quot;select history.branch_id, bank, branch from history\n&quot; +
143            &quot;join branches on branches._id=history.branch_id\n&quot; +
144            &quot;join banks on banks._id=branches.bank_id&quot;)
145    LiveData&lt;List&lt;HistoryCustomized&gt;&gt; getAll();
146
147    @Query(&quot;select history.branch_id, bank, branch from history\n&quot; +
148            &quot;join branches on branches._id=history.branch_id\n&quot; +
149            &quot;join banks on banks._id=branches.bank_id\n&quot; +
150            &quot;where bank like :token or branch like :token&quot;)
151    LiveData&lt;List&lt;HistoryCustomized&gt;&gt; searchHistoryByBankOrBranch(String token);
152
153    @Transaction
154    @Insert
155    void insert(History history);
156}
157

I know there is some problem with threading because whenever I run this in emulator (BranchFragment), it crash quickly, but when I debug it, it show proper data, though not insert entry in history table. Room has many threading issues.

Here is AppDatabase:

1public class BranchDetailsFragment extends Fragment implements View.OnClickListener {
2
3    private final Application application;
4    private final int branchIid;
5
6    private FragBranchDetailsBinding binding;//view-binding
7
8    public BranchDetailsFragment(Application application, int branchIid) {
9        //saving branchId
10    }
11
12    @Nullable
13    @Override
14    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
15        //normal stuff
16    }
17
18    @Override
19    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
20        super.onViewCreated(view, savedInstanceState);
21        BranchDetailsViewModel branchDetailsViewModel = new BranchDetailsViewModel(application);
22        
23        //inserting entry in history table
24        HistoryViewModel historyViewModel = new HistoryViewModel(application);
25        History history = new History();
26        history.setBranchId(branchIid);
27        historyViewModel.insert(history);
28        
29        //fetching data from branches table
30        branchDetailsViewModel.getBranchCustomizedById(branchIid).observe(getViewLifecycleOwner(), new Observer&lt;BranchCustomized&gt;() {
31            @Override
32            public void onChanged(BranchCustomized branchCustomized) {
33                //get branch details and show them
34            }
35        });
36    }
37}
38@Entity(tableName = &quot;branches&quot;)
39public class Branch {
40    @PrimaryKey(autoGenerate = true)
41    @ColumnInfo(name = &quot;_id&quot;)
42    private int id;
43
44    @ColumnInfo(name = &quot;bank_id&quot;)
45    private int bankId;
46    
47    public int getId() {
48        return id;
49    }
50
51    public void setId(int id) {
52        this.id = id;
53    }
54
55    public int getBankId() {
56        return bankId;
57    }
58
59    public void setBankId(int bankId) {
60        this.bankId = bankId;
61    }
62
63}
64@Entity(tableName = &quot;history&quot;, foreignKeys = @ForeignKey(entity = Branch.class, parentColumns = &quot;_id&quot;, childColumns = &quot;branch_id&quot;))
65public class History {
66    @PrimaryKey(autoGenerate = true)
67    @ColumnInfo(name = &quot;_id&quot;)
68    private int id;
69
70    @ColumnInfo(name = &quot;branch_id&quot;)
71    private int branchId;
72
73    public int getId() {
74        return id;
75    }
76
77    public void setId(int id) {
78        this.id = id;
79    }
80
81    public int getBranchId() {
82        return branchId;
83    }
84
85    public void setBranchId(int branchId) {
86        this.branchId = branchId;
87    }
88}
89public class HistoryViewModel extends AndroidViewModel {
90    final HistoryRepository repository;
91
92    public HistoryViewModel(Application application) {
93        super(application);
94        repository = new HistoryRepository(application);
95    }
96
97    public LiveData&lt;List&lt;HistoryCustomized&gt;&gt; getAll(){
98        return repository.getAll();
99    }
100
101    public LiveData&lt;List&lt;HistoryCustomized&gt;&gt;  searchHistoryByBankOrBranch(String token){
102        return repository.searchHistoryByBankOrBranch(token);
103    }
104
105    public void insert(History history){
106        repository.insert(history);
107    }
108}
109public class HistoryRepository {
110    private final HistoryDao dao;
111    AppDatabase db;
112
113
114    public HistoryRepository(Application application) {
115        db = AppDatabase.getInstance(application);
116        dao = db.getHistoryDao();
117    }
118
119    public LiveData&lt;List&lt;HistoryCustomized&gt;&gt; getAll() {
120        return dao.getAll();
121    }
122
123    public LiveData&lt;List&lt;HistoryCustomized&gt;&gt; searchHistoryByBankOrBranch(String token) {
124        return dao.searchHistoryByBankOrBranch(token);
125    }
126
127    public void insert(History history){
128        try {
129            db.getTransactionExecutor().execute(new Runnable() {
130                @Override
131                public void run() {
132                    dao.insert(history);
133                }
134            });
135        }catch (NullPointerException e){
136            e.printStackTrace();
137        }
138    }
139}
140@Dao
141public interface HistoryDao {
142    @Query(&quot;select history.branch_id, bank, branch from history\n&quot; +
143            &quot;join branches on branches._id=history.branch_id\n&quot; +
144            &quot;join banks on banks._id=branches.bank_id&quot;)
145    LiveData&lt;List&lt;HistoryCustomized&gt;&gt; getAll();
146
147    @Query(&quot;select history.branch_id, bank, branch from history\n&quot; +
148            &quot;join branches on branches._id=history.branch_id\n&quot; +
149            &quot;join banks on banks._id=branches.bank_id\n&quot; +
150            &quot;where bank like :token or branch like :token&quot;)
151    LiveData&lt;List&lt;HistoryCustomized&gt;&gt; searchHistoryByBankOrBranch(String token);
152
153    @Transaction
154    @Insert
155    void insert(History history);
156}
157@Database(entities = {Branch.class, History.class},
158        version = 1, exportSchema = false)
159public abstract class AppDatabase extends RoomDatabase {
160
161    public abstract BranchesDao getBranchesDao();
162    public abstract HistoryDao getHistoryDao();
163
164    public static AppDatabase getInstance(final Context context) {
165        dbInstance = buildDatabaseInstance(context);
166        return dbInstance;
167    }
168
169    private static AppDatabase buildDatabaseInstance(Context context) {
170        return Room.databaseBuilder(context,
171                AppDatabase.class,
172                &quot;branch.db&quot;)
173                .createFromAsset(&quot;branch.db&quot;)
174                .fallbackToDestructiveMigration()
175                .build();
176    }
177
178    public static void cleanUp() {
179        dbInstance = null;
180    }
181
182}
183

Here is HistoryDao_Impl(autogenerated by Room library):

1public class BranchDetailsFragment extends Fragment implements View.OnClickListener {
2
3    private final Application application;
4    private final int branchIid;
5
6    private FragBranchDetailsBinding binding;//view-binding
7
8    public BranchDetailsFragment(Application application, int branchIid) {
9        //saving branchId
10    }
11
12    @Nullable
13    @Override
14    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
15        //normal stuff
16    }
17
18    @Override
19    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
20        super.onViewCreated(view, savedInstanceState);
21        BranchDetailsViewModel branchDetailsViewModel = new BranchDetailsViewModel(application);
22        
23        //inserting entry in history table
24        HistoryViewModel historyViewModel = new HistoryViewModel(application);
25        History history = new History();
26        history.setBranchId(branchIid);
27        historyViewModel.insert(history);
28        
29        //fetching data from branches table
30        branchDetailsViewModel.getBranchCustomizedById(branchIid).observe(getViewLifecycleOwner(), new Observer&lt;BranchCustomized&gt;() {
31            @Override
32            public void onChanged(BranchCustomized branchCustomized) {
33                //get branch details and show them
34            }
35        });
36    }
37}
38@Entity(tableName = &quot;branches&quot;)
39public class Branch {
40    @PrimaryKey(autoGenerate = true)
41    @ColumnInfo(name = &quot;_id&quot;)
42    private int id;
43
44    @ColumnInfo(name = &quot;bank_id&quot;)
45    private int bankId;
46    
47    public int getId() {
48        return id;
49    }
50
51    public void setId(int id) {
52        this.id = id;
53    }
54
55    public int getBankId() {
56        return bankId;
57    }
58
59    public void setBankId(int bankId) {
60        this.bankId = bankId;
61    }
62
63}
64@Entity(tableName = &quot;history&quot;, foreignKeys = @ForeignKey(entity = Branch.class, parentColumns = &quot;_id&quot;, childColumns = &quot;branch_id&quot;))
65public class History {
66    @PrimaryKey(autoGenerate = true)
67    @ColumnInfo(name = &quot;_id&quot;)
68    private int id;
69
70    @ColumnInfo(name = &quot;branch_id&quot;)
71    private int branchId;
72
73    public int getId() {
74        return id;
75    }
76
77    public void setId(int id) {
78        this.id = id;
79    }
80
81    public int getBranchId() {
82        return branchId;
83    }
84
85    public void setBranchId(int branchId) {
86        this.branchId = branchId;
87    }
88}
89public class HistoryViewModel extends AndroidViewModel {
90    final HistoryRepository repository;
91
92    public HistoryViewModel(Application application) {
93        super(application);
94        repository = new HistoryRepository(application);
95    }
96
97    public LiveData&lt;List&lt;HistoryCustomized&gt;&gt; getAll(){
98        return repository.getAll();
99    }
100
101    public LiveData&lt;List&lt;HistoryCustomized&gt;&gt;  searchHistoryByBankOrBranch(String token){
102        return repository.searchHistoryByBankOrBranch(token);
103    }
104
105    public void insert(History history){
106        repository.insert(history);
107    }
108}
109public class HistoryRepository {
110    private final HistoryDao dao;
111    AppDatabase db;
112
113
114    public HistoryRepository(Application application) {
115        db = AppDatabase.getInstance(application);
116        dao = db.getHistoryDao();
117    }
118
119    public LiveData&lt;List&lt;HistoryCustomized&gt;&gt; getAll() {
120        return dao.getAll();
121    }
122
123    public LiveData&lt;List&lt;HistoryCustomized&gt;&gt; searchHistoryByBankOrBranch(String token) {
124        return dao.searchHistoryByBankOrBranch(token);
125    }
126
127    public void insert(History history){
128        try {
129            db.getTransactionExecutor().execute(new Runnable() {
130                @Override
131                public void run() {
132                    dao.insert(history);
133                }
134            });
135        }catch (NullPointerException e){
136            e.printStackTrace();
137        }
138    }
139}
140@Dao
141public interface HistoryDao {
142    @Query(&quot;select history.branch_id, bank, branch from history\n&quot; +
143            &quot;join branches on branches._id=history.branch_id\n&quot; +
144            &quot;join banks on banks._id=branches.bank_id&quot;)
145    LiveData&lt;List&lt;HistoryCustomized&gt;&gt; getAll();
146
147    @Query(&quot;select history.branch_id, bank, branch from history\n&quot; +
148            &quot;join branches on branches._id=history.branch_id\n&quot; +
149            &quot;join banks on banks._id=branches.bank_id\n&quot; +
150            &quot;where bank like :token or branch like :token&quot;)
151    LiveData&lt;List&lt;HistoryCustomized&gt;&gt; searchHistoryByBankOrBranch(String token);
152
153    @Transaction
154    @Insert
155    void insert(History history);
156}
157@Database(entities = {Branch.class, History.class},
158        version = 1, exportSchema = false)
159public abstract class AppDatabase extends RoomDatabase {
160
161    public abstract BranchesDao getBranchesDao();
162    public abstract HistoryDao getHistoryDao();
163
164    public static AppDatabase getInstance(final Context context) {
165        dbInstance = buildDatabaseInstance(context);
166        return dbInstance;
167    }
168
169    private static AppDatabase buildDatabaseInstance(Context context) {
170        return Room.databaseBuilder(context,
171                AppDatabase.class,
172                &quot;branch.db&quot;)
173                .createFromAsset(&quot;branch.db&quot;)
174                .fallbackToDestructiveMigration()
175                .build();
176    }
177
178    public static void cleanUp() {
179        dbInstance = null;
180    }
181
182}
183@SuppressWarnings({&quot;unchecked&quot;, &quot;deprecation&quot;})
184public final class HistoryDao_Impl implements HistoryDao {
185  private final RoomDatabase __db;
186
187  private final EntityInsertionAdapter&lt;History&gt; __insertionAdapterOfHistory;
188
189  public HistoryDao_Impl(RoomDatabase __db) {
190    this.__db = __db;
191    this.__insertionAdapterOfHistory = new EntityInsertionAdapter&lt;History&gt;(__db) {
192      @Override
193      public String createQuery() {
194        return &quot;INSERT OR ABORT INTO `history` (`_id`,`branch_id`) VALUES (nullif(?, 0),?)&quot;;
195      }
196
197      @Override
198      public void bind(SupportSQLiteStatement stmt, History value) {
199        stmt.bindLong(1, value.getId());
200        stmt.bindLong(2, value.getBranchId());
201      }
202    };
203  }
204
205  @Override
206  public void insert(final History history) {
207    __db.assertNotSuspendingTransaction();
208    __db.beginTransaction();
209    try {
210      __insertionAdapterOfHistory.insert(history);
211      __db.setTransactionSuccessful();
212    } finally {
213      __db.endTransaction();
214    }
215  }
216  
217      @Override
218      protected void finalize() {
219        _statement.release();
220      }
221    });
222  }
223}
224

Here is image showing underline sql: enter image description here

Here are the error logs (but it not happen when I debug):

1public class BranchDetailsFragment extends Fragment implements View.OnClickListener {
2
3    private final Application application;
4    private final int branchIid;
5
6    private FragBranchDetailsBinding binding;//view-binding
7
8    public BranchDetailsFragment(Application application, int branchIid) {
9        //saving branchId
10    }
11
12    @Nullable
13    @Override
14    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
15        //normal stuff
16    }
17
18    @Override
19    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
20        super.onViewCreated(view, savedInstanceState);
21        BranchDetailsViewModel branchDetailsViewModel = new BranchDetailsViewModel(application);
22        
23        //inserting entry in history table
24        HistoryViewModel historyViewModel = new HistoryViewModel(application);
25        History history = new History();
26        history.setBranchId(branchIid);
27        historyViewModel.insert(history);
28        
29        //fetching data from branches table
30        branchDetailsViewModel.getBranchCustomizedById(branchIid).observe(getViewLifecycleOwner(), new Observer&lt;BranchCustomized&gt;() {
31            @Override
32            public void onChanged(BranchCustomized branchCustomized) {
33                //get branch details and show them
34            }
35        });
36    }
37}
38@Entity(tableName = &quot;branches&quot;)
39public class Branch {
40    @PrimaryKey(autoGenerate = true)
41    @ColumnInfo(name = &quot;_id&quot;)
42    private int id;
43
44    @ColumnInfo(name = &quot;bank_id&quot;)
45    private int bankId;
46    
47    public int getId() {
48        return id;
49    }
50
51    public void setId(int id) {
52        this.id = id;
53    }
54
55    public int getBankId() {
56        return bankId;
57    }
58
59    public void setBankId(int bankId) {
60        this.bankId = bankId;
61    }
62
63}
64@Entity(tableName = &quot;history&quot;, foreignKeys = @ForeignKey(entity = Branch.class, parentColumns = &quot;_id&quot;, childColumns = &quot;branch_id&quot;))
65public class History {
66    @PrimaryKey(autoGenerate = true)
67    @ColumnInfo(name = &quot;_id&quot;)
68    private int id;
69
70    @ColumnInfo(name = &quot;branch_id&quot;)
71    private int branchId;
72
73    public int getId() {
74        return id;
75    }
76
77    public void setId(int id) {
78        this.id = id;
79    }
80
81    public int getBranchId() {
82        return branchId;
83    }
84
85    public void setBranchId(int branchId) {
86        this.branchId = branchId;
87    }
88}
89public class HistoryViewModel extends AndroidViewModel {
90    final HistoryRepository repository;
91
92    public HistoryViewModel(Application application) {
93        super(application);
94        repository = new HistoryRepository(application);
95    }
96
97    public LiveData&lt;List&lt;HistoryCustomized&gt;&gt; getAll(){
98        return repository.getAll();
99    }
100
101    public LiveData&lt;List&lt;HistoryCustomized&gt;&gt;  searchHistoryByBankOrBranch(String token){
102        return repository.searchHistoryByBankOrBranch(token);
103    }
104
105    public void insert(History history){
106        repository.insert(history);
107    }
108}
109public class HistoryRepository {
110    private final HistoryDao dao;
111    AppDatabase db;
112
113
114    public HistoryRepository(Application application) {
115        db = AppDatabase.getInstance(application);
116        dao = db.getHistoryDao();
117    }
118
119    public LiveData&lt;List&lt;HistoryCustomized&gt;&gt; getAll() {
120        return dao.getAll();
121    }
122
123    public LiveData&lt;List&lt;HistoryCustomized&gt;&gt; searchHistoryByBankOrBranch(String token) {
124        return dao.searchHistoryByBankOrBranch(token);
125    }
126
127    public void insert(History history){
128        try {
129            db.getTransactionExecutor().execute(new Runnable() {
130                @Override
131                public void run() {
132                    dao.insert(history);
133                }
134            });
135        }catch (NullPointerException e){
136            e.printStackTrace();
137        }
138    }
139}
140@Dao
141public interface HistoryDao {
142    @Query(&quot;select history.branch_id, bank, branch from history\n&quot; +
143            &quot;join branches on branches._id=history.branch_id\n&quot; +
144            &quot;join banks on banks._id=branches.bank_id&quot;)
145    LiveData&lt;List&lt;HistoryCustomized&gt;&gt; getAll();
146
147    @Query(&quot;select history.branch_id, bank, branch from history\n&quot; +
148            &quot;join branches on branches._id=history.branch_id\n&quot; +
149            &quot;join banks on banks._id=branches.bank_id\n&quot; +
150            &quot;where bank like :token or branch like :token&quot;)
151    LiveData&lt;List&lt;HistoryCustomized&gt;&gt; searchHistoryByBankOrBranch(String token);
152
153    @Transaction
154    @Insert
155    void insert(History history);
156}
157@Database(entities = {Branch.class, History.class},
158        version = 1, exportSchema = false)
159public abstract class AppDatabase extends RoomDatabase {
160
161    public abstract BranchesDao getBranchesDao();
162    public abstract HistoryDao getHistoryDao();
163
164    public static AppDatabase getInstance(final Context context) {
165        dbInstance = buildDatabaseInstance(context);
166        return dbInstance;
167    }
168
169    private static AppDatabase buildDatabaseInstance(Context context) {
170        return Room.databaseBuilder(context,
171                AppDatabase.class,
172                &quot;branch.db&quot;)
173                .createFromAsset(&quot;branch.db&quot;)
174                .fallbackToDestructiveMigration()
175                .build();
176    }
177
178    public static void cleanUp() {
179        dbInstance = null;
180    }
181
182}
183@SuppressWarnings({&quot;unchecked&quot;, &quot;deprecation&quot;})
184public final class HistoryDao_Impl implements HistoryDao {
185  private final RoomDatabase __db;
186
187  private final EntityInsertionAdapter&lt;History&gt; __insertionAdapterOfHistory;
188
189  public HistoryDao_Impl(RoomDatabase __db) {
190    this.__db = __db;
191    this.__insertionAdapterOfHistory = new EntityInsertionAdapter&lt;History&gt;(__db) {
192      @Override
193      public String createQuery() {
194        return &quot;INSERT OR ABORT INTO `history` (`_id`,`branch_id`) VALUES (nullif(?, 0),?)&quot;;
195      }
196
197      @Override
198      public void bind(SupportSQLiteStatement stmt, History value) {
199        stmt.bindLong(1, value.getId());
200        stmt.bindLong(2, value.getBranchId());
201      }
202    };
203  }
204
205  @Override
206  public void insert(final History history) {
207    __db.assertNotSuspendingTransaction();
208    __db.beginTransaction();
209    try {
210      __insertionAdapterOfHistory.insert(history);
211      __db.setTransactionSuccessful();
212    } finally {
213      __db.endTransaction();
214    }
215  }
216  
217      @Override
218      protected void finalize() {
219        _statement.release();
220      }
221    });
222  }
223}
22404-06 13:58:35.080 2471-2471/com.appsbharti.bharatbankdetails E/dalvikvm: Could not find class 'android.graphics.drawable.RippleDrawable', referenced from method com.google.android.material.button.MaterialButtonHelper.createBackground
22504-06 13:58:35.080 2471-2471/com.appsbharti.bharatbankdetails E/dalvikvm: Could not find class 'android.graphics.drawable.RippleDrawable', referenced from method com.google.android.material.button.MaterialButtonHelper.setRippleColor
22604-06 13:58:35.090 2471-2471/com.appsbharti.bharatbankdetails E/dalvikvm: Could not find class 'com.google.android.material.chip.Chip$2', referenced from method com.google.android.material.chip.Chip.initOutlineProvider
22704-06 13:58:35.090 2471-2471/com.appsbharti.bharatbankdetails E/dalvikvm: Could not find class 'android.graphics.drawable.RippleDrawable', referenced from method com.google.android.material.chip.Chip.updateFrameworkRippleBackground
22804-06 13:58:35.100 2471-2471/com.appsbharti.bharatbankdetails E/dalvikvm: Could not find class 'android.graphics.drawable.RippleDrawable', referenced from method com.google.android.material.chip.ChipDrawable.updateFrameworkCloseIconRipple
22904-06 13:58:35.770 2471-2498/com.appsbharti.bharatbankdetails E/AndroidRuntime: FATAL EXCEPTION: arch_disk_io_2
230    android.database.sqlite.SQLiteConstraintException: foreign key constraint failed (code 19)
231        at android.database.sqlite.SQLiteConnection.nativeExecuteForLastInsertedRowId(Native Method)
232        at android.database.sqlite.SQLiteConnection.executeForLastInsertedRowId(SQLiteConnection.java:775)
233        at android.database.sqlite.SQLiteSession.executeForLastInsertedRowId(SQLiteSession.java:788)
234        at android.database.sqlite.SQLiteStatement.executeInsert(SQLiteStatement.java:86)
235        at androidx.sqlite.db.framework.FrameworkSQLiteStatement.executeInsert(FrameworkSQLiteStatement.java:51)
236        at androidx.room.EntityInsertionAdapter.insert(EntityInsertionAdapter.java:64)
237        at com.appsbharti.bharatbankdetails.Daos.HistoryDao_Impl.insert(HistoryDao_Impl.java:48)
238        at com.appsbharti.bharatbankdetails.Repositories.HistoryRepository$1.run(HistoryRepository.java:41)
239        at androidx.room.TransactionExecutor$1.run(TransactionExecutor.java:45)
240        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
241        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
242        at java.lang.Thread.run(Thread.java:856)
24304-06 13:58:39.170 1395-1481/system_process E/ThrottleService: problem during onPollAlarm: java.lang.IllegalStateException: problem parsing stats: java.io.FileNotFoundException: /proc/net/xt_qtaguid/iface_stat_all: open failed: ENOENT (No such file or directory)
244

Sometimes It throw this error:

1public class BranchDetailsFragment extends Fragment implements View.OnClickListener {
2
3    private final Application application;
4    private final int branchIid;
5
6    private FragBranchDetailsBinding binding;//view-binding
7
8    public BranchDetailsFragment(Application application, int branchIid) {
9        //saving branchId
10    }
11
12    @Nullable
13    @Override
14    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
15        //normal stuff
16    }
17
18    @Override
19    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
20        super.onViewCreated(view, savedInstanceState);
21        BranchDetailsViewModel branchDetailsViewModel = new BranchDetailsViewModel(application);
22        
23        //inserting entry in history table
24        HistoryViewModel historyViewModel = new HistoryViewModel(application);
25        History history = new History();
26        history.setBranchId(branchIid);
27        historyViewModel.insert(history);
28        
29        //fetching data from branches table
30        branchDetailsViewModel.getBranchCustomizedById(branchIid).observe(getViewLifecycleOwner(), new Observer&lt;BranchCustomized&gt;() {
31            @Override
32            public void onChanged(BranchCustomized branchCustomized) {
33                //get branch details and show them
34            }
35        });
36    }
37}
38@Entity(tableName = &quot;branches&quot;)
39public class Branch {
40    @PrimaryKey(autoGenerate = true)
41    @ColumnInfo(name = &quot;_id&quot;)
42    private int id;
43
44    @ColumnInfo(name = &quot;bank_id&quot;)
45    private int bankId;
46    
47    public int getId() {
48        return id;
49    }
50
51    public void setId(int id) {
52        this.id = id;
53    }
54
55    public int getBankId() {
56        return bankId;
57    }
58
59    public void setBankId(int bankId) {
60        this.bankId = bankId;
61    }
62
63}
64@Entity(tableName = &quot;history&quot;, foreignKeys = @ForeignKey(entity = Branch.class, parentColumns = &quot;_id&quot;, childColumns = &quot;branch_id&quot;))
65public class History {
66    @PrimaryKey(autoGenerate = true)
67    @ColumnInfo(name = &quot;_id&quot;)
68    private int id;
69
70    @ColumnInfo(name = &quot;branch_id&quot;)
71    private int branchId;
72
73    public int getId() {
74        return id;
75    }
76
77    public void setId(int id) {
78        this.id = id;
79    }
80
81    public int getBranchId() {
82        return branchId;
83    }
84
85    public void setBranchId(int branchId) {
86        this.branchId = branchId;
87    }
88}
89public class HistoryViewModel extends AndroidViewModel {
90    final HistoryRepository repository;
91
92    public HistoryViewModel(Application application) {
93        super(application);
94        repository = new HistoryRepository(application);
95    }
96
97    public LiveData&lt;List&lt;HistoryCustomized&gt;&gt; getAll(){
98        return repository.getAll();
99    }
100
101    public LiveData&lt;List&lt;HistoryCustomized&gt;&gt;  searchHistoryByBankOrBranch(String token){
102        return repository.searchHistoryByBankOrBranch(token);
103    }
104
105    public void insert(History history){
106        repository.insert(history);
107    }
108}
109public class HistoryRepository {
110    private final HistoryDao dao;
111    AppDatabase db;
112
113
114    public HistoryRepository(Application application) {
115        db = AppDatabase.getInstance(application);
116        dao = db.getHistoryDao();
117    }
118
119    public LiveData&lt;List&lt;HistoryCustomized&gt;&gt; getAll() {
120        return dao.getAll();
121    }
122
123    public LiveData&lt;List&lt;HistoryCustomized&gt;&gt; searchHistoryByBankOrBranch(String token) {
124        return dao.searchHistoryByBankOrBranch(token);
125    }
126
127    public void insert(History history){
128        try {
129            db.getTransactionExecutor().execute(new Runnable() {
130                @Override
131                public void run() {
132                    dao.insert(history);
133                }
134            });
135        }catch (NullPointerException e){
136            e.printStackTrace();
137        }
138    }
139}
140@Dao
141public interface HistoryDao {
142    @Query(&quot;select history.branch_id, bank, branch from history\n&quot; +
143            &quot;join branches on branches._id=history.branch_id\n&quot; +
144            &quot;join banks on banks._id=branches.bank_id&quot;)
145    LiveData&lt;List&lt;HistoryCustomized&gt;&gt; getAll();
146
147    @Query(&quot;select history.branch_id, bank, branch from history\n&quot; +
148            &quot;join branches on branches._id=history.branch_id\n&quot; +
149            &quot;join banks on banks._id=branches.bank_id\n&quot; +
150            &quot;where bank like :token or branch like :token&quot;)
151    LiveData&lt;List&lt;HistoryCustomized&gt;&gt; searchHistoryByBankOrBranch(String token);
152
153    @Transaction
154    @Insert
155    void insert(History history);
156}
157@Database(entities = {Branch.class, History.class},
158        version = 1, exportSchema = false)
159public abstract class AppDatabase extends RoomDatabase {
160
161    public abstract BranchesDao getBranchesDao();
162    public abstract HistoryDao getHistoryDao();
163
164    public static AppDatabase getInstance(final Context context) {
165        dbInstance = buildDatabaseInstance(context);
166        return dbInstance;
167    }
168
169    private static AppDatabase buildDatabaseInstance(Context context) {
170        return Room.databaseBuilder(context,
171                AppDatabase.class,
172                &quot;branch.db&quot;)
173                .createFromAsset(&quot;branch.db&quot;)
174                .fallbackToDestructiveMigration()
175                .build();
176    }
177
178    public static void cleanUp() {
179        dbInstance = null;
180    }
181
182}
183@SuppressWarnings({&quot;unchecked&quot;, &quot;deprecation&quot;})
184public final class HistoryDao_Impl implements HistoryDao {
185  private final RoomDatabase __db;
186
187  private final EntityInsertionAdapter&lt;History&gt; __insertionAdapterOfHistory;
188
189  public HistoryDao_Impl(RoomDatabase __db) {
190    this.__db = __db;
191    this.__insertionAdapterOfHistory = new EntityInsertionAdapter&lt;History&gt;(__db) {
192      @Override
193      public String createQuery() {
194        return &quot;INSERT OR ABORT INTO `history` (`_id`,`branch_id`) VALUES (nullif(?, 0),?)&quot;;
195      }
196
197      @Override
198      public void bind(SupportSQLiteStatement stmt, History value) {
199        stmt.bindLong(1, value.getId());
200        stmt.bindLong(2, value.getBranchId());
201      }
202    };
203  }
204
205  @Override
206  public void insert(final History history) {
207    __db.assertNotSuspendingTransaction();
208    __db.beginTransaction();
209    try {
210      __insertionAdapterOfHistory.insert(history);
211      __db.setTransactionSuccessful();
212    } finally {
213      __db.endTransaction();
214    }
215  }
216  
217      @Override
218      protected void finalize() {
219        _statement.release();
220      }
221    });
222  }
223}
22404-06 13:58:35.080 2471-2471/com.appsbharti.bharatbankdetails E/dalvikvm: Could not find class 'android.graphics.drawable.RippleDrawable', referenced from method com.google.android.material.button.MaterialButtonHelper.createBackground
22504-06 13:58:35.080 2471-2471/com.appsbharti.bharatbankdetails E/dalvikvm: Could not find class 'android.graphics.drawable.RippleDrawable', referenced from method com.google.android.material.button.MaterialButtonHelper.setRippleColor
22604-06 13:58:35.090 2471-2471/com.appsbharti.bharatbankdetails E/dalvikvm: Could not find class 'com.google.android.material.chip.Chip$2', referenced from method com.google.android.material.chip.Chip.initOutlineProvider
22704-06 13:58:35.090 2471-2471/com.appsbharti.bharatbankdetails E/dalvikvm: Could not find class 'android.graphics.drawable.RippleDrawable', referenced from method com.google.android.material.chip.Chip.updateFrameworkRippleBackground
22804-06 13:58:35.100 2471-2471/com.appsbharti.bharatbankdetails E/dalvikvm: Could not find class 'android.graphics.drawable.RippleDrawable', referenced from method com.google.android.material.chip.ChipDrawable.updateFrameworkCloseIconRipple
22904-06 13:58:35.770 2471-2498/com.appsbharti.bharatbankdetails E/AndroidRuntime: FATAL EXCEPTION: arch_disk_io_2
230    android.database.sqlite.SQLiteConstraintException: foreign key constraint failed (code 19)
231        at android.database.sqlite.SQLiteConnection.nativeExecuteForLastInsertedRowId(Native Method)
232        at android.database.sqlite.SQLiteConnection.executeForLastInsertedRowId(SQLiteConnection.java:775)
233        at android.database.sqlite.SQLiteSession.executeForLastInsertedRowId(SQLiteSession.java:788)
234        at android.database.sqlite.SQLiteStatement.executeInsert(SQLiteStatement.java:86)
235        at androidx.sqlite.db.framework.FrameworkSQLiteStatement.executeInsert(FrameworkSQLiteStatement.java:51)
236        at androidx.room.EntityInsertionAdapter.insert(EntityInsertionAdapter.java:64)
237        at com.appsbharti.bharatbankdetails.Daos.HistoryDao_Impl.insert(HistoryDao_Impl.java:48)
238        at com.appsbharti.bharatbankdetails.Repositories.HistoryRepository$1.run(HistoryRepository.java:41)
239        at androidx.room.TransactionExecutor$1.run(TransactionExecutor.java:45)
240        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
241        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
242        at java.lang.Thread.run(Thread.java:856)
24304-06 13:58:39.170 1395-1481/system_process E/ThrottleService: problem during onPollAlarm: java.lang.IllegalStateException: problem parsing stats: java.io.FileNotFoundException: /proc/net/xt_qtaguid/iface_stat_all: open failed: ENOENT (No such file or directory)
244--------- beginning of crash
2452021-04-07 17:05:06.152 4247-4279/com.appsbharti.bharatbankdetails E/AndroidRuntime: FATAL EXCEPTION: arch_disk_io_2
246    Process: com.appsbharti.bharatbankdetails, PID: 4247
247    android.database.sqlite.SQLiteReadOnlyDatabaseException: attempt to write a readonly database (code 1032 SQLITE_READONLY_DBMOVED)
248        at android.database.sqlite.SQLiteConnection.nativeExecuteForString(Native Method)
249        at android.database.sqlite.SQLiteConnection.executeForString(SQLiteConnection.java:655)
250        at android.database.sqlite.SQLiteConnection.setJournalMode(SQLiteConnection.java:336)
251        at android.database.sqlite.SQLiteConnection.setWalModeFromConfiguration(SQLiteConnection.java:298)
252        at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:217)
253        at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:195)
254        at android.database.sqlite.SQLiteConnectionPool.openConnectionLocked(SQLiteConnectionPool.java:503)
255        at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:204)
256        at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:196)
257        at android.database.sqlite.SQLiteDatabase.openInner(SQLiteDatabase.java:880)
258        at android.database.sqlite.SQLiteDatabase.open(SQLiteDatabase.java:865)
259        at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:739)
260        at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:729)
261        at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:355)
262        at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:298)
263        at androidx.sqlite.db.framework.FrameworkSQLiteOpenHelper$OpenHelper.getWritableSupportDatabase(FrameworkSQLiteOpenHelper.java:92)
264        at androidx.sqlite.db.framework.FrameworkSQLiteOpenHelper.getWritableDatabase(FrameworkSQLiteOpenHelper.java:53)
265        at androidx.room.SQLiteCopyOpenHelper.getWritableDatabase(SQLiteCopyOpenHelper.java:90)
266        at androidx.room.RoomDatabase.inTransaction(RoomDatabase.java:476)
267        at androidx.room.RoomDatabase.assertNotSuspendingTransaction(RoomDatabase.java:281)
268        at com.appsbharti.bharatbankdetails.Daos.HistoryDao_Impl.insert(HistoryDao_Impl.java:45)
269        at com.appsbharti.bharatbankdetails.Repositories.HistoryRepository$1.run(HistoryRepository.java:37)
270        at androidx.room.TransactionExecutor$1.run(TransactionExecutor.java:45)
271        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
272        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
273        at java.lang.Thread.run(Thread.java:764)
274

I have added android_metadata table manually when I throws error of can't fine locale en_US.

1public class BranchDetailsFragment extends Fragment implements View.OnClickListener {
2
3    private final Application application;
4    private final int branchIid;
5
6    private FragBranchDetailsBinding binding;//view-binding
7
8    public BranchDetailsFragment(Application application, int branchIid) {
9        //saving branchId
10    }
11
12    @Nullable
13    @Override
14    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
15        //normal stuff
16    }
17
18    @Override
19    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
20        super.onViewCreated(view, savedInstanceState);
21        BranchDetailsViewModel branchDetailsViewModel = new BranchDetailsViewModel(application);
22        
23        //inserting entry in history table
24        HistoryViewModel historyViewModel = new HistoryViewModel(application);
25        History history = new History();
26        history.setBranchId(branchIid);
27        historyViewModel.insert(history);
28        
29        //fetching data from branches table
30        branchDetailsViewModel.getBranchCustomizedById(branchIid).observe(getViewLifecycleOwner(), new Observer&lt;BranchCustomized&gt;() {
31            @Override
32            public void onChanged(BranchCustomized branchCustomized) {
33                //get branch details and show them
34            }
35        });
36    }
37}
38@Entity(tableName = &quot;branches&quot;)
39public class Branch {
40    @PrimaryKey(autoGenerate = true)
41    @ColumnInfo(name = &quot;_id&quot;)
42    private int id;
43
44    @ColumnInfo(name = &quot;bank_id&quot;)
45    private int bankId;
46    
47    public int getId() {
48        return id;
49    }
50
51    public void setId(int id) {
52        this.id = id;
53    }
54
55    public int getBankId() {
56        return bankId;
57    }
58
59    public void setBankId(int bankId) {
60        this.bankId = bankId;
61    }
62
63}
64@Entity(tableName = &quot;history&quot;, foreignKeys = @ForeignKey(entity = Branch.class, parentColumns = &quot;_id&quot;, childColumns = &quot;branch_id&quot;))
65public class History {
66    @PrimaryKey(autoGenerate = true)
67    @ColumnInfo(name = &quot;_id&quot;)
68    private int id;
69
70    @ColumnInfo(name = &quot;branch_id&quot;)
71    private int branchId;
72
73    public int getId() {
74        return id;
75    }
76
77    public void setId(int id) {
78        this.id = id;
79    }
80
81    public int getBranchId() {
82        return branchId;
83    }
84
85    public void setBranchId(int branchId) {
86        this.branchId = branchId;
87    }
88}
89public class HistoryViewModel extends AndroidViewModel {
90    final HistoryRepository repository;
91
92    public HistoryViewModel(Application application) {
93        super(application);
94        repository = new HistoryRepository(application);
95    }
96
97    public LiveData&lt;List&lt;HistoryCustomized&gt;&gt; getAll(){
98        return repository.getAll();
99    }
100
101    public LiveData&lt;List&lt;HistoryCustomized&gt;&gt;  searchHistoryByBankOrBranch(String token){
102        return repository.searchHistoryByBankOrBranch(token);
103    }
104
105    public void insert(History history){
106        repository.insert(history);
107    }
108}
109public class HistoryRepository {
110    private final HistoryDao dao;
111    AppDatabase db;
112
113
114    public HistoryRepository(Application application) {
115        db = AppDatabase.getInstance(application);
116        dao = db.getHistoryDao();
117    }
118
119    public LiveData&lt;List&lt;HistoryCustomized&gt;&gt; getAll() {
120        return dao.getAll();
121    }
122
123    public LiveData&lt;List&lt;HistoryCustomized&gt;&gt; searchHistoryByBankOrBranch(String token) {
124        return dao.searchHistoryByBankOrBranch(token);
125    }
126
127    public void insert(History history){
128        try {
129            db.getTransactionExecutor().execute(new Runnable() {
130                @Override
131                public void run() {
132                    dao.insert(history);
133                }
134            });
135        }catch (NullPointerException e){
136            e.printStackTrace();
137        }
138    }
139}
140@Dao
141public interface HistoryDao {
142    @Query(&quot;select history.branch_id, bank, branch from history\n&quot; +
143            &quot;join branches on branches._id=history.branch_id\n&quot; +
144            &quot;join banks on banks._id=branches.bank_id&quot;)
145    LiveData&lt;List&lt;HistoryCustomized&gt;&gt; getAll();
146
147    @Query(&quot;select history.branch_id, bank, branch from history\n&quot; +
148            &quot;join branches on branches._id=history.branch_id\n&quot; +
149            &quot;join banks on banks._id=branches.bank_id\n&quot; +
150            &quot;where bank like :token or branch like :token&quot;)
151    LiveData&lt;List&lt;HistoryCustomized&gt;&gt; searchHistoryByBankOrBranch(String token);
152
153    @Transaction
154    @Insert
155    void insert(History history);
156}
157@Database(entities = {Branch.class, History.class},
158        version = 1, exportSchema = false)
159public abstract class AppDatabase extends RoomDatabase {
160
161    public abstract BranchesDao getBranchesDao();
162    public abstract HistoryDao getHistoryDao();
163
164    public static AppDatabase getInstance(final Context context) {
165        dbInstance = buildDatabaseInstance(context);
166        return dbInstance;
167    }
168
169    private static AppDatabase buildDatabaseInstance(Context context) {
170        return Room.databaseBuilder(context,
171                AppDatabase.class,
172                &quot;branch.db&quot;)
173                .createFromAsset(&quot;branch.db&quot;)
174                .fallbackToDestructiveMigration()
175                .build();
176    }
177
178    public static void cleanUp() {
179        dbInstance = null;
180    }
181
182}
183@SuppressWarnings({&quot;unchecked&quot;, &quot;deprecation&quot;})
184public final class HistoryDao_Impl implements HistoryDao {
185  private final RoomDatabase __db;
186
187  private final EntityInsertionAdapter&lt;History&gt; __insertionAdapterOfHistory;
188
189  public HistoryDao_Impl(RoomDatabase __db) {
190    this.__db = __db;
191    this.__insertionAdapterOfHistory = new EntityInsertionAdapter&lt;History&gt;(__db) {
192      @Override
193      public String createQuery() {
194        return &quot;INSERT OR ABORT INTO `history` (`_id`,`branch_id`) VALUES (nullif(?, 0),?)&quot;;
195      }
196
197      @Override
198      public void bind(SupportSQLiteStatement stmt, History value) {
199        stmt.bindLong(1, value.getId());
200        stmt.bindLong(2, value.getBranchId());
201      }
202    };
203  }
204
205  @Override
206  public void insert(final History history) {
207    __db.assertNotSuspendingTransaction();
208    __db.beginTransaction();
209    try {
210      __insertionAdapterOfHistory.insert(history);
211      __db.setTransactionSuccessful();
212    } finally {
213      __db.endTransaction();
214    }
215  }
216  
217      @Override
218      protected void finalize() {
219        _statement.release();
220      }
221    });
222  }
223}
22404-06 13:58:35.080 2471-2471/com.appsbharti.bharatbankdetails E/dalvikvm: Could not find class 'android.graphics.drawable.RippleDrawable', referenced from method com.google.android.material.button.MaterialButtonHelper.createBackground
22504-06 13:58:35.080 2471-2471/com.appsbharti.bharatbankdetails E/dalvikvm: Could not find class 'android.graphics.drawable.RippleDrawable', referenced from method com.google.android.material.button.MaterialButtonHelper.setRippleColor
22604-06 13:58:35.090 2471-2471/com.appsbharti.bharatbankdetails E/dalvikvm: Could not find class 'com.google.android.material.chip.Chip$2', referenced from method com.google.android.material.chip.Chip.initOutlineProvider
22704-06 13:58:35.090 2471-2471/com.appsbharti.bharatbankdetails E/dalvikvm: Could not find class 'android.graphics.drawable.RippleDrawable', referenced from method com.google.android.material.chip.Chip.updateFrameworkRippleBackground
22804-06 13:58:35.100 2471-2471/com.appsbharti.bharatbankdetails E/dalvikvm: Could not find class 'android.graphics.drawable.RippleDrawable', referenced from method com.google.android.material.chip.ChipDrawable.updateFrameworkCloseIconRipple
22904-06 13:58:35.770 2471-2498/com.appsbharti.bharatbankdetails E/AndroidRuntime: FATAL EXCEPTION: arch_disk_io_2
230    android.database.sqlite.SQLiteConstraintException: foreign key constraint failed (code 19)
231        at android.database.sqlite.SQLiteConnection.nativeExecuteForLastInsertedRowId(Native Method)
232        at android.database.sqlite.SQLiteConnection.executeForLastInsertedRowId(SQLiteConnection.java:775)
233        at android.database.sqlite.SQLiteSession.executeForLastInsertedRowId(SQLiteSession.java:788)
234        at android.database.sqlite.SQLiteStatement.executeInsert(SQLiteStatement.java:86)
235        at androidx.sqlite.db.framework.FrameworkSQLiteStatement.executeInsert(FrameworkSQLiteStatement.java:51)
236        at androidx.room.EntityInsertionAdapter.insert(EntityInsertionAdapter.java:64)
237        at com.appsbharti.bharatbankdetails.Daos.HistoryDao_Impl.insert(HistoryDao_Impl.java:48)
238        at com.appsbharti.bharatbankdetails.Repositories.HistoryRepository$1.run(HistoryRepository.java:41)
239        at androidx.room.TransactionExecutor$1.run(TransactionExecutor.java:45)
240        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
241        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
242        at java.lang.Thread.run(Thread.java:856)
24304-06 13:58:39.170 1395-1481/system_process E/ThrottleService: problem during onPollAlarm: java.lang.IllegalStateException: problem parsing stats: java.io.FileNotFoundException: /proc/net/xt_qtaguid/iface_stat_all: open failed: ENOENT (No such file or directory)
244--------- beginning of crash
2452021-04-07 17:05:06.152 4247-4279/com.appsbharti.bharatbankdetails E/AndroidRuntime: FATAL EXCEPTION: arch_disk_io_2
246    Process: com.appsbharti.bharatbankdetails, PID: 4247
247    android.database.sqlite.SQLiteReadOnlyDatabaseException: attempt to write a readonly database (code 1032 SQLITE_READONLY_DBMOVED)
248        at android.database.sqlite.SQLiteConnection.nativeExecuteForString(Native Method)
249        at android.database.sqlite.SQLiteConnection.executeForString(SQLiteConnection.java:655)
250        at android.database.sqlite.SQLiteConnection.setJournalMode(SQLiteConnection.java:336)
251        at android.database.sqlite.SQLiteConnection.setWalModeFromConfiguration(SQLiteConnection.java:298)
252        at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:217)
253        at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:195)
254        at android.database.sqlite.SQLiteConnectionPool.openConnectionLocked(SQLiteConnectionPool.java:503)
255        at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:204)
256        at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:196)
257        at android.database.sqlite.SQLiteDatabase.openInner(SQLiteDatabase.java:880)
258        at android.database.sqlite.SQLiteDatabase.open(SQLiteDatabase.java:865)
259        at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:739)
260        at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:729)
261        at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:355)
262        at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:298)
263        at androidx.sqlite.db.framework.FrameworkSQLiteOpenHelper$OpenHelper.getWritableSupportDatabase(FrameworkSQLiteOpenHelper.java:92)
264        at androidx.sqlite.db.framework.FrameworkSQLiteOpenHelper.getWritableDatabase(FrameworkSQLiteOpenHelper.java:53)
265        at androidx.room.SQLiteCopyOpenHelper.getWritableDatabase(SQLiteCopyOpenHelper.java:90)
266        at androidx.room.RoomDatabase.inTransaction(RoomDatabase.java:476)
267        at androidx.room.RoomDatabase.assertNotSuspendingTransaction(RoomDatabase.java:281)
268        at com.appsbharti.bharatbankdetails.Daos.HistoryDao_Impl.insert(HistoryDao_Impl.java:45)
269        at com.appsbharti.bharatbankdetails.Repositories.HistoryRepository$1.run(HistoryRepository.java:37)
270        at androidx.room.TransactionExecutor$1.run(TransactionExecutor.java:45)
271        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
272        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
273        at java.lang.Thread.run(Thread.java:764)
274CREATE TABLE &quot;android_metadata&quot; (
275    &quot;locale&quot;    TEXT
276);
277

and added en_US entry to locale column.

ANSWER

Answered 2021-Apr-07 at 13:14

OK there was a simple issue behind those all errors. I haven't fetched AppDatabase inside synchronized block.

Inside AppDatabse class, I changed newInsance method from:

1public class BranchDetailsFragment extends Fragment implements View.OnClickListener {
2
3    private final Application application;
4    private final int branchIid;
5
6    private FragBranchDetailsBinding binding;//view-binding
7
8    public BranchDetailsFragment(Application application, int branchIid) {
9        //saving branchId
10    }
11
12    @Nullable
13    @Override
14    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
15        //normal stuff
16    }
17
18    @Override
19    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
20        super.onViewCreated(view, savedInstanceState);
21        BranchDetailsViewModel branchDetailsViewModel = new BranchDetailsViewModel(application);
22        
23        //inserting entry in history table
24        HistoryViewModel historyViewModel = new HistoryViewModel(application);
25        History history = new History();
26        history.setBranchId(branchIid);
27        historyViewModel.insert(history);
28        
29        //fetching data from branches table
30        branchDetailsViewModel.getBranchCustomizedById(branchIid).observe(getViewLifecycleOwner(), new Observer&lt;BranchCustomized&gt;() {
31            @Override
32            public void onChanged(BranchCustomized branchCustomized) {
33                //get branch details and show them
34            }
35        });
36    }
37}
38@Entity(tableName = &quot;branches&quot;)
39public class Branch {
40    @PrimaryKey(autoGenerate = true)
41    @ColumnInfo(name = &quot;_id&quot;)
42    private int id;
43
44    @ColumnInfo(name = &quot;bank_id&quot;)
45    private int bankId;
46    
47    public int getId() {
48        return id;
49    }
50
51    public void setId(int id) {
52        this.id = id;
53    }
54
55    public int getBankId() {
56        return bankId;
57    }
58
59    public void setBankId(int bankId) {
60        this.bankId = bankId;
61    }
62
63}
64@Entity(tableName = &quot;history&quot;, foreignKeys = @ForeignKey(entity = Branch.class, parentColumns = &quot;_id&quot;, childColumns = &quot;branch_id&quot;))
65public class History {
66    @PrimaryKey(autoGenerate = true)
67    @ColumnInfo(name = &quot;_id&quot;)
68    private int id;
69
70    @ColumnInfo(name = &quot;branch_id&quot;)
71    private int branchId;
72
73    public int getId() {
74        return id;
75    }
76
77    public void setId(int id) {
78        this.id = id;
79    }
80
81    public int getBranchId() {
82        return branchId;
83    }
84
85    public void setBranchId(int branchId) {
86        this.branchId = branchId;
87    }
88}
89public class HistoryViewModel extends AndroidViewModel {
90    final HistoryRepository repository;
91
92    public HistoryViewModel(Application application) {
93        super(application);
94        repository = new HistoryRepository(application);
95    }
96
97    public LiveData&lt;List&lt;HistoryCustomized&gt;&gt; getAll(){
98        return repository.getAll();
99    }
100
101    public LiveData&lt;List&lt;HistoryCustomized&gt;&gt;  searchHistoryByBankOrBranch(String token){
102        return repository.searchHistoryByBankOrBranch(token);
103    }
104
105    public void insert(History history){
106        repository.insert(history);
107    }
108}
109public class HistoryRepository {
110    private final HistoryDao dao;
111    AppDatabase db;
112
113
114    public HistoryRepository(Application application) {
115        db = AppDatabase.getInstance(application);
116        dao = db.getHistoryDao();
117    }
118
119    public LiveData&lt;List&lt;HistoryCustomized&gt;&gt; getAll() {
120        return dao.getAll();
121    }
122
123    public LiveData&lt;List&lt;HistoryCustomized&gt;&gt; searchHistoryByBankOrBranch(String token) {
124        return dao.searchHistoryByBankOrBranch(token);
125    }
126
127    public void insert(History history){
128        try {
129            db.getTransactionExecutor().execute(new Runnable() {
130                @Override
131                public void run() {
132                    dao.insert(history);
133                }
134            });
135        }catch (NullPointerException e){
136            e.printStackTrace();
137        }
138    }
139}
140@Dao
141public interface HistoryDao {
142    @Query(&quot;select history.branch_id, bank, branch from history\n&quot; +
143            &quot;join branches on branches._id=history.branch_id\n&quot; +
144            &quot;join banks on banks._id=branches.bank_id&quot;)
145    LiveData&lt;List&lt;HistoryCustomized&gt;&gt; getAll();
146
147    @Query(&quot;select history.branch_id, bank, branch from history\n&quot; +
148            &quot;join branches on branches._id=history.branch_id\n&quot; +
149            &quot;join banks on banks._id=branches.bank_id\n&quot; +
150            &quot;where bank like :token or branch like :token&quot;)
151    LiveData&lt;List&lt;HistoryCustomized&gt;&gt; searchHistoryByBankOrBranch(String token);
152
153    @Transaction
154    @Insert
155    void insert(History history);
156}
157@Database(entities = {Branch.class, History.class},
158        version = 1, exportSchema = false)
159public abstract class AppDatabase extends RoomDatabase {
160
161    public abstract BranchesDao getBranchesDao();
162    public abstract HistoryDao getHistoryDao();
163
164    public static AppDatabase getInstance(final Context context) {
165        dbInstance = buildDatabaseInstance(context);
166        return dbInstance;
167    }
168
169    private static AppDatabase buildDatabaseInstance(Context context) {
170        return Room.databaseBuilder(context,
171                AppDatabase.class,
172                &quot;branch.db&quot;)
173                .createFromAsset(&quot;branch.db&quot;)
174                .fallbackToDestructiveMigration()
175                .build();
176    }
177
178    public static void cleanUp() {
179        dbInstance = null;
180    }
181
182}
183@SuppressWarnings({&quot;unchecked&quot;, &quot;deprecation&quot;})
184public final class HistoryDao_Impl implements HistoryDao {
185  private final RoomDatabase __db;
186
187  private final EntityInsertionAdapter&lt;History&gt; __insertionAdapterOfHistory;
188
189  public HistoryDao_Impl(RoomDatabase __db) {
190    this.__db = __db;
191    this.__insertionAdapterOfHistory = new EntityInsertionAdapter&lt;History&gt;(__db) {
192      @Override
193      public String createQuery() {
194        return &quot;INSERT OR ABORT INTO `history` (`_id`,`branch_id`) VALUES (nullif(?, 0),?)&quot;;
195      }
196
197      @Override
198      public void bind(SupportSQLiteStatement stmt, History value) {
199        stmt.bindLong(1, value.getId());
200        stmt.bindLong(2, value.getBranchId());
201      }
202    };
203  }
204
205  @Override
206  public void insert(final History history) {
207    __db.assertNotSuspendingTransaction();
208    __db.beginTransaction();
209    try {
210      __insertionAdapterOfHistory.insert(history);
211      __db.setTransactionSuccessful();
212    } finally {
213      __db.endTransaction();
214    }
215  }
216  
217      @Override
218      protected void finalize() {
219        _statement.release();
220      }
221    });
222  }
223}
22404-06 13:58:35.080 2471-2471/com.appsbharti.bharatbankdetails E/dalvikvm: Could not find class 'android.graphics.drawable.RippleDrawable', referenced from method com.google.android.material.button.MaterialButtonHelper.createBackground
22504-06 13:58:35.080 2471-2471/com.appsbharti.bharatbankdetails E/dalvikvm: Could not find class 'android.graphics.drawable.RippleDrawable', referenced from method com.google.android.material.button.MaterialButtonHelper.setRippleColor
22604-06 13:58:35.090 2471-2471/com.appsbharti.bharatbankdetails E/dalvikvm: Could not find class 'com.google.android.material.chip.Chip$2', referenced from method com.google.android.material.chip.Chip.initOutlineProvider
22704-06 13:58:35.090 2471-2471/com.appsbharti.bharatbankdetails E/dalvikvm: Could not find class 'android.graphics.drawable.RippleDrawable', referenced from method com.google.android.material.chip.Chip.updateFrameworkRippleBackground
22804-06 13:58:35.100 2471-2471/com.appsbharti.bharatbankdetails E/dalvikvm: Could not find class 'android.graphics.drawable.RippleDrawable', referenced from method com.google.android.material.chip.ChipDrawable.updateFrameworkCloseIconRipple
22904-06 13:58:35.770 2471-2498/com.appsbharti.bharatbankdetails E/AndroidRuntime: FATAL EXCEPTION: arch_disk_io_2
230    android.database.sqlite.SQLiteConstraintException: foreign key constraint failed (code 19)
231        at android.database.sqlite.SQLiteConnection.nativeExecuteForLastInsertedRowId(Native Method)
232        at android.database.sqlite.SQLiteConnection.executeForLastInsertedRowId(SQLiteConnection.java:775)
233        at android.database.sqlite.SQLiteSession.executeForLastInsertedRowId(SQLiteSession.java:788)
234        at android.database.sqlite.SQLiteStatement.executeInsert(SQLiteStatement.java:86)
235        at androidx.sqlite.db.framework.FrameworkSQLiteStatement.executeInsert(FrameworkSQLiteStatement.java:51)
236        at androidx.room.EntityInsertionAdapter.insert(EntityInsertionAdapter.java:64)
237        at com.appsbharti.bharatbankdetails.Daos.HistoryDao_Impl.insert(HistoryDao_Impl.java:48)
238        at com.appsbharti.bharatbankdetails.Repositories.HistoryRepository$1.run(HistoryRepository.java:41)
239        at androidx.room.TransactionExecutor$1.run(TransactionExecutor.java:45)
240        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
241        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
242        at java.lang.Thread.run(Thread.java:856)
24304-06 13:58:39.170 1395-1481/system_process E/ThrottleService: problem during onPollAlarm: java.lang.IllegalStateException: problem parsing stats: java.io.FileNotFoundException: /proc/net/xt_qtaguid/iface_stat_all: open failed: ENOENT (No such file or directory)
244--------- beginning of crash
2452021-04-07 17:05:06.152 4247-4279/com.appsbharti.bharatbankdetails E/AndroidRuntime: FATAL EXCEPTION: arch_disk_io_2
246    Process: com.appsbharti.bharatbankdetails, PID: 4247
247    android.database.sqlite.SQLiteReadOnlyDatabaseException: attempt to write a readonly database (code 1032 SQLITE_READONLY_DBMOVED)
248        at android.database.sqlite.SQLiteConnection.nativeExecuteForString(Native Method)
249        at android.database.sqlite.SQLiteConnection.executeForString(SQLiteConnection.java:655)
250        at android.database.sqlite.SQLiteConnection.setJournalMode(SQLiteConnection.java:336)
251        at android.database.sqlite.SQLiteConnection.setWalModeFromConfiguration(SQLiteConnection.java:298)
252        at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:217)
253        at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:195)
254        at android.database.sqlite.SQLiteConnectionPool.openConnectionLocked(SQLiteConnectionPool.java:503)
255        at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:204)
256        at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:196)
257        at android.database.sqlite.SQLiteDatabase.openInner(SQLiteDatabase.java:880)
258        at android.database.sqlite.SQLiteDatabase.open(SQLiteDatabase.java:865)
259        at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:739)
260        at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:729)
261        at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:355)
262        at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:298)
263        at androidx.sqlite.db.framework.FrameworkSQLiteOpenHelper$OpenHelper.getWritableSupportDatabase(FrameworkSQLiteOpenHelper.java:92)
264        at androidx.sqlite.db.framework.FrameworkSQLiteOpenHelper.getWritableDatabase(FrameworkSQLiteOpenHelper.java:53)
265        at androidx.room.SQLiteCopyOpenHelper.getWritableDatabase(SQLiteCopyOpenHelper.java:90)
266        at androidx.room.RoomDatabase.inTransaction(RoomDatabase.java:476)
267        at androidx.room.RoomDatabase.assertNotSuspendingTransaction(RoomDatabase.java:281)
268        at com.appsbharti.bharatbankdetails.Daos.HistoryDao_Impl.insert(HistoryDao_Impl.java:45)
269        at com.appsbharti.bharatbankdetails.Repositories.HistoryRepository$1.run(HistoryRepository.java:37)
270        at androidx.room.TransactionExecutor$1.run(TransactionExecutor.java:45)
271        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
272        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
273        at java.lang.Thread.run(Thread.java:764)
274CREATE TABLE &quot;android_metadata&quot; (
275    &quot;locale&quot;    TEXT
276);
277public static AppDatabase getInstance(final Context context) {
278    dbInstance = buildDatabaseInstance(context);
279    return dbInstance;
280}
281

to

1public class BranchDetailsFragment extends Fragment implements View.OnClickListener {
2
3    private final Application application;
4    private final int branchIid;
5
6    private FragBranchDetailsBinding binding;//view-binding
7
8    public BranchDetailsFragment(Application application, int branchIid) {
9        //saving branchId
10    }
11
12    @Nullable
13    @Override
14    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
15        //normal stuff
16    }
17
18    @Override
19    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
20        super.onViewCreated(view, savedInstanceState);
21        BranchDetailsViewModel branchDetailsViewModel = new BranchDetailsViewModel(application);
22        
23        //inserting entry in history table
24        HistoryViewModel historyViewModel = new HistoryViewModel(application);
25        History history = new History();
26        history.setBranchId(branchIid);
27        historyViewModel.insert(history);
28        
29        //fetching data from branches table
30        branchDetailsViewModel.getBranchCustomizedById(branchIid).observe(getViewLifecycleOwner(), new Observer&lt;BranchCustomized&gt;() {
31            @Override
32            public void onChanged(BranchCustomized branchCustomized) {
33                //get branch details and show them
34            }
35        });
36    }
37}
38@Entity(tableName = &quot;branches&quot;)
39public class Branch {
40    @PrimaryKey(autoGenerate = true)
41    @ColumnInfo(name = &quot;_id&quot;)
42    private int id;
43
44    @ColumnInfo(name = &quot;bank_id&quot;)
45    private int bankId;
46    
47    public int getId() {
48        return id;
49    }
50
51    public void setId(int id) {
52        this.id = id;
53    }
54
55    public int getBankId() {
56        return bankId;
57    }
58
59    public void setBankId(int bankId) {
60        this.bankId = bankId;
61    }
62
63}
64@Entity(tableName = &quot;history&quot;, foreignKeys = @ForeignKey(entity = Branch.class, parentColumns = &quot;_id&quot;, childColumns = &quot;branch_id&quot;))
65public class History {
66    @PrimaryKey(autoGenerate = true)
67    @ColumnInfo(name = &quot;_id&quot;)
68    private int id;
69
70    @ColumnInfo(name = &quot;branch_id&quot;)
71    private int branchId;
72
73    public int getId() {
74        return id;
75    }
76
77    public void setId(int id) {
78        this.id = id;
79    }
80
81    public int getBranchId() {
82        return branchId;
83    }
84
85    public void setBranchId(int branchId) {
86        this.branchId = branchId;
87    }
88}
89public class HistoryViewModel extends AndroidViewModel {
90    final HistoryRepository repository;
91
92    public HistoryViewModel(Application application) {
93        super(application);
94        repository = new HistoryRepository(application);
95    }
96
97    public LiveData&lt;List&lt;HistoryCustomized&gt;&gt; getAll(){
98        return repository.getAll();
99    }
100
101    public LiveData&lt;List&lt;HistoryCustomized&gt;&gt;  searchHistoryByBankOrBranch(String token){
102        return repository.searchHistoryByBankOrBranch(token);
103    }
104
105    public void insert(History history){
106        repository.insert(history);
107    }
108}
109public class HistoryRepository {
110    private final HistoryDao dao;
111    AppDatabase db;
112
113
114    public HistoryRepository(Application application) {
115        db = AppDatabase.getInstance(application);
116        dao = db.getHistoryDao();
117    }
118
119    public LiveData&lt;List&lt;HistoryCustomized&gt;&gt; getAll() {
120        return dao.getAll();
121    }
122
123    public LiveData&lt;List&lt;HistoryCustomized&gt;&gt; searchHistoryByBankOrBranch(String token) {
124        return dao.searchHistoryByBankOrBranch(token);
125    }
126
127    public void insert(History history){
128        try {
129            db.getTransactionExecutor().execute(new Runnable() {
130                @Override
131                public void run() {
132                    dao.insert(history);
133                }
134            });
135        }catch (NullPointerException e){
136            e.printStackTrace();
137        }
138    }
139}
140@Dao
141public interface HistoryDao {
142    @Query(&quot;select history.branch_id, bank, branch from history\n&quot; +
143            &quot;join branches on branches._id=history.branch_id\n&quot; +
144            &quot;join banks on banks._id=branches.bank_id&quot;)
145    LiveData&lt;List&lt;HistoryCustomized&gt;&gt; getAll();
146
147    @Query(&quot;select history.branch_id, bank, branch from history\n&quot; +
148            &quot;join branches on branches._id=history.branch_id\n&quot; +
149            &quot;join banks on banks._id=branches.bank_id\n&quot; +
150            &quot;where bank like :token or branch like :token&quot;)
151    LiveData&lt;List&lt;HistoryCustomized&gt;&gt; searchHistoryByBankOrBranch(String token);
152
153    @Transaction
154    @Insert
155    void insert(History history);
156}
157@Database(entities = {Branch.class, History.class},
158        version = 1, exportSchema = false)
159public abstract class AppDatabase extends RoomDatabase {
160
161    public abstract BranchesDao getBranchesDao();
162    public abstract HistoryDao getHistoryDao();
163
164    public static AppDatabase getInstance(final Context context) {
165        dbInstance = buildDatabaseInstance(context);
166        return dbInstance;
167    }
168
169    private static AppDatabase buildDatabaseInstance(Context context) {
170        return Room.databaseBuilder(context,
171                AppDatabase.class,
172                &quot;branch.db&quot;)
173                .createFromAsset(&quot;branch.db&quot;)
174                .fallbackToDestructiveMigration()
175                .build();
176    }
177
178    public static void cleanUp() {
179        dbInstance = null;
180    }
181
182}
183@SuppressWarnings({&quot;unchecked&quot;, &quot;deprecation&quot;})
184public final class HistoryDao_Impl implements HistoryDao {
185  private final RoomDatabase __db;
186
187  private final EntityInsertionAdapter&lt;History&gt; __insertionAdapterOfHistory;
188
189  public HistoryDao_Impl(RoomDatabase __db) {
190    this.__db = __db;
191    this.__insertionAdapterOfHistory = new EntityInsertionAdapter&lt;History&gt;(__db) {
192      @Override
193      public String createQuery() {
194        return &quot;INSERT OR ABORT INTO `history` (`_id`,`branch_id`) VALUES (nullif(?, 0),?)&quot;;
195      }
196
197      @Override
198      public void bind(SupportSQLiteStatement stmt, History value) {
199        stmt.bindLong(1, value.getId());
200        stmt.bindLong(2, value.getBranchId());
201      }
202    };
203  }
204
205  @Override
206  public void insert(final History history) {
207    __db.assertNotSuspendingTransaction();
208    __db.beginTransaction();
209    try {
210      __insertionAdapterOfHistory.insert(history);
211      __db.setTransactionSuccessful();
212    } finally {
213      __db.endTransaction();
214    }
215  }
216  
217      @Override
218      protected void finalize() {
219        _statement.release();
220      }
221    });
222  }
223}
22404-06 13:58:35.080 2471-2471/com.appsbharti.bharatbankdetails E/dalvikvm: Could not find class 'android.graphics.drawable.RippleDrawable', referenced from method com.google.android.material.button.MaterialButtonHelper.createBackground
22504-06 13:58:35.080 2471-2471/com.appsbharti.bharatbankdetails E/dalvikvm: Could not find class 'android.graphics.drawable.RippleDrawable', referenced from method com.google.android.material.button.MaterialButtonHelper.setRippleColor
22604-06 13:58:35.090 2471-2471/com.appsbharti.bharatbankdetails E/dalvikvm: Could not find class 'com.google.android.material.chip.Chip$2', referenced from method com.google.android.material.chip.Chip.initOutlineProvider
22704-06 13:58:35.090 2471-2471/com.appsbharti.bharatbankdetails E/dalvikvm: Could not find class 'android.graphics.drawable.RippleDrawable', referenced from method com.google.android.material.chip.Chip.updateFrameworkRippleBackground
22804-06 13:58:35.100 2471-2471/com.appsbharti.bharatbankdetails E/dalvikvm: Could not find class 'android.graphics.drawable.RippleDrawable', referenced from method com.google.android.material.chip.ChipDrawable.updateFrameworkCloseIconRipple
22904-06 13:58:35.770 2471-2498/com.appsbharti.bharatbankdetails E/AndroidRuntime: FATAL EXCEPTION: arch_disk_io_2
230    android.database.sqlite.SQLiteConstraintException: foreign key constraint failed (code 19)
231        at android.database.sqlite.SQLiteConnection.nativeExecuteForLastInsertedRowId(Native Method)
232        at android.database.sqlite.SQLiteConnection.executeForLastInsertedRowId(SQLiteConnection.java:775)
233        at android.database.sqlite.SQLiteSession.executeForLastInsertedRowId(SQLiteSession.java:788)
234        at android.database.sqlite.SQLiteStatement.executeInsert(SQLiteStatement.java:86)
235        at androidx.sqlite.db.framework.FrameworkSQLiteStatement.executeInsert(FrameworkSQLiteStatement.java:51)
236        at androidx.room.EntityInsertionAdapter.insert(EntityInsertionAdapter.java:64)
237        at com.appsbharti.bharatbankdetails.Daos.HistoryDao_Impl.insert(HistoryDao_Impl.java:48)
238        at com.appsbharti.bharatbankdetails.Repositories.HistoryRepository$1.run(HistoryRepository.java:41)
239        at androidx.room.TransactionExecutor$1.run(TransactionExecutor.java:45)
240        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
241        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
242        at java.lang.Thread.run(Thread.java:856)
24304-06 13:58:39.170 1395-1481/system_process E/ThrottleService: problem during onPollAlarm: java.lang.IllegalStateException: problem parsing stats: java.io.FileNotFoundException: /proc/net/xt_qtaguid/iface_stat_all: open failed: ENOENT (No such file or directory)
244--------- beginning of crash
2452021-04-07 17:05:06.152 4247-4279/com.appsbharti.bharatbankdetails E/AndroidRuntime: FATAL EXCEPTION: arch_disk_io_2
246    Process: com.appsbharti.bharatbankdetails, PID: 4247
247    android.database.sqlite.SQLiteReadOnlyDatabaseException: attempt to write a readonly database (code 1032 SQLITE_READONLY_DBMOVED)
248        at android.database.sqlite.SQLiteConnection.nativeExecuteForString(Native Method)
249        at android.database.sqlite.SQLiteConnection.executeForString(SQLiteConnection.java:655)
250        at android.database.sqlite.SQLiteConnection.setJournalMode(SQLiteConnection.java:336)
251        at android.database.sqlite.SQLiteConnection.setWalModeFromConfiguration(SQLiteConnection.java:298)
252        at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:217)
253        at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:195)
254        at android.database.sqlite.SQLiteConnectionPool.openConnectionLocked(SQLiteConnectionPool.java:503)
255        at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:204)
256        at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:196)
257        at android.database.sqlite.SQLiteDatabase.openInner(SQLiteDatabase.java:880)
258        at android.database.sqlite.SQLiteDatabase.open(SQLiteDatabase.java:865)
259        at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:739)
260        at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:729)
261        at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:355)
262        at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:298)
263        at androidx.sqlite.db.framework.FrameworkSQLiteOpenHelper$OpenHelper.getWritableSupportDatabase(FrameworkSQLiteOpenHelper.java:92)
264        at androidx.sqlite.db.framework.FrameworkSQLiteOpenHelper.getWritableDatabase(FrameworkSQLiteOpenHelper.java:53)
265        at androidx.room.SQLiteCopyOpenHelper.getWritableDatabase(SQLiteCopyOpenHelper.java:90)
266        at androidx.room.RoomDatabase.inTransaction(RoomDatabase.java:476)
267        at androidx.room.RoomDatabase.assertNotSuspendingTransaction(RoomDatabase.java:281)
268        at com.appsbharti.bharatbankdetails.Daos.HistoryDao_Impl.insert(HistoryDao_Impl.java:45)
269        at com.appsbharti.bharatbankdetails.Repositories.HistoryRepository$1.run(HistoryRepository.java:37)
270        at androidx.room.TransactionExecutor$1.run(TransactionExecutor.java:45)
271        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
272        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
273        at java.lang.Thread.run(Thread.java:764)
274CREATE TABLE &quot;android_metadata&quot; (
275    &quot;locale&quot;    TEXT
276);
277public static AppDatabase getInstance(final Context context) {
278    dbInstance = buildDatabaseInstance(context);
279    return dbInstance;
280}
281public static AppDatabase getInstance(final Context context) {
282    if (dbInstance == null)
283        synchronized (AppDatabase.class) {
284            if (dbInstance == null)
285                dbInstance = buildDatabaseInstance(context);
286         }
287//  dbInstance = buildDatabaseInstance(context);
288    return dbInstance;
289}
290

Problem is that, Room implicitly call getReadableDatabase() not getWritableDatabse() of SqliteOpenHelperclass while fetching query results.

To fetched BranchDetails, I created AppDatabase instance with read-only access inside BranchDetailsRepository.

I fetched same read-only instance inside HistoryRepository(as AppDatbase follows Singleton patter).

So when I called insert(History history), it throws error.

There was no issue of Foreign Key.

Trigger which I created using SqliteStudio also working fine without any problem, no issue with that either.

Source https://stackoverflow.com/questions/66965010

QUESTION

Where to Save ViewModel State in Android's MVVM?

Asked 2020-Dec-25 at 07:21

As a beginner to Android development, I am trying to clean up my codebase from my first app by converting it to the recommended MVVM structure. What I am currently stuck on, is trying to figure out the best way to store my view model's state.

In this example, the state I need to store is simply an ArrayList of strings (indicating which checkboxes in a recyclerview are checked). I am currently storing this ArrayList inside of my ViewModel as a field, wrapped inside of a MutableLivedata object, which my activity observes. This method of storing the ViewModel state as a field does not seem viable in the long run. I can imagine as my app grows my ViewModel classes would get quite bloated and messy.

I currently use a Firebase Realtime Database to store my data that I need persisted, accessed through a repository just as Android Architecture recommends. My ViewModel's state, however, does not need to be persisted after the app closes, so it would definitely not make sense to make network calls to my Firebase Database for it.

My question is: Where would make the most sense to save my ViewModel's state? The semi-sensible options I see in front of me are saving it as fields in my ViewModel class (my current approach), saving it in a Room database (and resetting the database each time the app is killed), or saving it as fields in my repository class (doesn't seem right). I'm open to suggestions!

ANSWER

Answered 2020-Dec-25 at 07:21

It depends on your needs:

  • If you want to keep state just for configuration changes, you do not need to do anything more. ViewModel will handle it for you.
  • If you want to see the same state when you come back to that screen after closing it, then I would recommend to use a local cache solution such as Room. You can create a repository on top of room and inject it into your Viewmodel.
  • If you want to keep state until application closes, you can also create an in-memory repository (a singleton repo with the state). When application is killed that memory will be reclaimed by the OS so that they will be cleared.

In any case storing data remotely does not seem to be the the solution that you are looking for.

I would also not rely on memory cache solution because of Android system memory reclaim situations.

You can go with the cache solution and clear your cache when you open the app again.

Source https://stackoverflow.com/questions/65377099

QUESTION

Android (Kotlin): Type mismatch in Observer

Asked 2020-Dec-16 at 04:36

I am implementing an MVVM Android architecture in which in the main application component (MainActivity), I listen to the ModelView's LiveData storage for any changes. However, in the following piece of code:

1private final var viewModel:ScheduleViewModel = ViewModelProviders.of(this).get(ScheduleViewModel::class.java)
2
3viewModel.getSchedule().observe(this, object:Observer&lt;String&gt; {
4    fun onChanged(feed:String){
5    }
6})
7

I get the following error:

1private final var viewModel:ScheduleViewModel = ViewModelProviders.of(this).get(ScheduleViewModel::class.java)
2
3viewModel.getSchedule().observe(this, object:Observer&lt;String&gt; {
4    fun onChanged(feed:String){
5    }
6})
7Required: Observer&lt;in String!&gt;
8Found: 
9

Below are my imports:

1private final var viewModel:ScheduleViewModel = ViewModelProviders.of(this).get(ScheduleViewModel::class.java)
2
3viewModel.getSchedule().observe(this, object:Observer&lt;String&gt; {
4    fun onChanged(feed:String){
5    }
6})
7Required: Observer&lt;in String!&gt;
8Found: 
9import android.os.Build
10import android.os.Bundle
11import android.util.Base64
12import androidx.annotation.Nullable
13import androidx.appcompat.app.AppCompatActivity
14import androidx.lifecycle.ViewModelProviders
15import androidx.loader.app.LoaderManager
16import androidx.loader.content.Loader
17import androidx.viewpager.widget.ViewPager
18import com.example.mvvmarchitecture.ui.main.TabsAdapter
19import com.google.android.material.tabs.TabLayout
20import java.io.InputStream
21import java.net.HttpURLConnection
22import java.net.URL
23import java.util.*
24

ANSWER

Answered 2020-Dec-16 at 03:36

To fix that, replace Observer<String> with Observer<in String>.

But even easier, use a lambda instead of an anonymous object, so you don't have to worry about matching up the type:

1private final var viewModel:ScheduleViewModel = ViewModelProviders.of(this).get(ScheduleViewModel::class.java)
2
3viewModel.getSchedule().observe(this, object:Observer&lt;String&gt; {
4    fun onChanged(feed:String){
5    }
6})
7Required: Observer&lt;in String!&gt;
8Found: 
9import android.os.Build
10import android.os.Bundle
11import android.util.Base64
12import androidx.annotation.Nullable
13import androidx.appcompat.app.AppCompatActivity
14import androidx.lifecycle.ViewModelProviders
15import androidx.loader.app.LoaderManager
16import androidx.loader.content.Loader
17import androidx.viewpager.widget.ViewPager
18import com.example.mvvmarchitecture.ui.main.TabsAdapter
19import com.google.android.material.tabs.TabLayout
20import java.io.InputStream
21import java.net.HttpURLConnection
22import java.net.URL
23import java.util.*
24viewModel.getSchedule().observe(this) { feed -&gt;
25    //...
26}
27

Source https://stackoverflow.com/questions/65316899

Community Discussions contain sources that include Stack Exchange Network

Tutorials and Learning Resources in Android Architecture

Tutorials and Learning Resources are not available at this moment for Android Architecture

Share this Page

share link

Get latest updates on Android Architecture