Failed to load AppCompat ActionBar with unknown error


I created a new app like directed in the book. I made the changes as directed in activity_quiz.xml. I get the following error

Failed to load AppCompat ActionBar with unknown error.
The following classes could not be instantiated:

  • (Open Class, Show Exception, Clear Cache)
  • (Open Class, Show Exception, Clear Cache)
  • (Open Class, Show Exception, Clear Cache)
    Exception Details java.lang.ClassNotFoundException: android.view.View$OnUnhandledKeyEventListener

I downloaded the latest Android Studio - Build 3.1.4. It was built on July 23, 2018
I have download API 28 and API 19

Are you seeing that error in the UI editor? That kind of thing happens all the time.

Try running your code to see if it works on a device/emulator. The UI editor sometimes has problems that are not caused by your code.

If you want to fix it, you can play around with some of the settings on the UI editor preview window. The buttons at the top let you change which version of Android you’re previewing the UI with along with some other things. Changing that Android version may fix the editor’s problem.

You are right. It does work when I run in emulator or on device. I tried the various versions. Nothing worked. And then after searching a bit, adding the following in build.gradle fixed it for me. I am still starting, so do not follow what is it doing, but guess it is manually picking a certain API version for some piece of work that does not seem to impact running the application in device or emulator but fixes the UI editor

configurations.all {
resolutionStrategy.eachDependency { DependencyResolveDetails details ->
def requested = details.requested
if ( == “”) {
if (!“multidex”)) {
details.useVersion “26.+”

1 Like

Thanks @salimv. I hit the same problem (frustrating to hit a snag on the very first example in the book). The addition to build.gradle worked.

Note to anyone else that does a copy & paste for the above code: You will likely have to fix the double quote characters after pasting the text.