user6456773 user6456773 - 1 year ago 226
Android Question

java.lang.IllegalMonitorStateException: object not locked by thread before notify() - onResponse

I am trying to set the adapter of a RecyclerView within the onCreate(). I read that the notifyDatasetChanged() can be invoked on the main thread only. But how can this be achieved? Here is my code so far:

RecyclerView recyclerViewSt;
List<GitHubstarredRepos> myDataSource = new ArrayList<>();
RecyclerView.Adapter myAdapter;

protected void onCreate(Bundle savedInstanceState) {

recyclerViewSt = (RecyclerView) findViewById(;
recyclerViewSt.setLayoutManager(new LinearLayoutManager(this));

myAdapter = new StarredReposAdapter(myDataSource, R.layout.list_item_starred_repo,


public void loadStarredRepos (View view){
GitHubStarredRepoAPI apiService =

Call<List<GitHubstarredRepos>> call = apiService.getStarredRepoName(newString);
call.enqueue(new Callback<List<GitHubstarredRepos>>() {
public void onResponse(Call<List<GitHubstarredRepos>> call, Response<List<GitHubstarredRepos>>
response) {



Thank you!

Answer Source

instead of notifying RecyclerView, Notify your Adapter.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download