Skip to content Skip to sidebar Skip to footer

Java.lang.noclassdeffounderror: Failed Resolution Of: Landroid/support/v4/view/keyeventcompat

I am going to enter a phone number, but when I type in the number, the app crash immediately. The following error occurred E/AndroidRuntime: FATAL EXCEPTION: main Pro

Solution 1:

I've found the reason, because when support_version is 27, the KeyEventCompat class is removed in support-v4 . We can see that in the dispatchKeyEvent method of AppCompatActivity as follow

@Override
public boolean dispatchKeyEvent(KeyEvent event) {
    if (KeyEventCompat.isCtrlPressed(event) &&
            event.getUnicodeChar(event.getMetaState() & ~KeyEvent.META_CTRL_MASK) == '<') {
        // Capture the Control-< and send focus to the ActionBar
        final int action = event.getAction();
        if (action == KeyEvent.ACTION_DOWN) {
            final ActionBar actionBar = getSupportActionBar();
            if (actionBar != null && actionBar.isShowing() && actionBar.requestFocus()) {
                mEatKeyUpEvent = true;
                returntrue;
            }
        } elseif (action == KeyEvent.ACTION_UP && mEatKeyUpEvent) {
            mEatKeyUpEvent = false;
            returntrue;
        }
    }
    return super.dispatchKeyEvent(event);
}

Executed to KeyEventCompat.isCtrlPressed (event), because can not find the class, so cause the app to crash

The solution is as follows:

  • Create a package called android.support.v4.view in your code
  • Copy the class KeyEventCompat and KeyEventCompatHoneycomb to this package
  • Rebuild project

Post a Comment for "Java.lang.noclassdeffounderror: Failed Resolution Of: Landroid/support/v4/view/keyeventcompat"