SnackBar - NoSuchMethodError:android.view.MotionEvent.getActionMasked

时间:2016-01-09 06:37:05

标签: android

我在模拟器API-7中运行此代码,

 FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Snackbar.make(findViewById(R.id.fragment), "Replace with your own action", Snackbar.LENGTH_LONG)
                        .setAction("Done", new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                   Toast.makeText(MainActivity.this, "Testing", Toast.LENGTH_SHORT).show();
                            }
                        }).show();
            }
        });
    }

错误:

java.lang.NoSuchMethodError: android.view.MotionEvent.getActionMasked

at android.support.design.widget.Snackbar$Behavior.onInterceptTouchEvent(Snackbar.java:823)
at android.support.design.widget.Snackbar$Behavior.onInterceptTouchEvent(Snackbar.java:811)
at android.support.design.widget.CoordinatorLayout.performIntercept(CoordinatorLayout.java:379)
at android.support.design.widget.CoordinatorLayout.onInterceptTouchEvent(CoordinatorLayout.java:418)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:803)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:822)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:822)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:822)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:822)
at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1659)
at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1107)
at android.app.Activity.dispatchTouchEvent(Activity.java:2061)
at android.support.v7.view.WindowCallbackWrapper.dispatchTouchEvent(WindowCallbackWrapper.java:60)
at android.support.v7.view.WindowCallbackWrapper.dispatchTouchEvent(WindowCallbackWrapper.java:60)
at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1643)
at android.view.ViewRoot.handleMessage(ViewRoot.java:1691)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4363)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
at dalvik.system.NativeStart.main(Native Method)

任何解决方案?

1 个答案:

答案 0 :(得分:1)

API 8及更高版本上存在

getActionMasked(),因此看起来Snackbar不能像目前所写的那样在API 7上使用。