-1
imgView.setImageResource(R.drawable.enable);

Image of Enabling Bluetooth is in res folder, and user imageView in XML and its perfectly works fine in nexus 6P(8.1.0) but the application crashes in OS (6.0.1)

Following error appears:

android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.

Is there any OS restriction? or any other way to fix this?

1 Answers1

2

You are trying to set it inside a thread. You cannot use ui components inside a thread. You have to use main or ui thread for that. You can try using it inside run on ui thread.

runOnUiThread(new Runnable() {
            @Override
            public void run() {
                imgView.setImageResource(R.drawable.enable);
            }
        });
Amit Jangid
  • 2,741
  • 1
  • 22
  • 28