AppCompatActivity is not working properly

2019-08-01 17:10发布

enter image description hereI am developing an app which uses AppCompatActivity. I have been struggling since so many days solving this error but no luck and no reply for such an answer on StackOverflow. The gradle is built successfully without any error. But when the app is installed in the device, I get a force close error.

I am attaching my Android Monitor(logcat) content here. Please help me with this.

java.lang.NoSuchMethodError:
android.support.v4.view.ViewCompat.setOnApplyWindowInsetsListener(Landroid/view/View;Landroid/support/v4/view/OnApplyWindowInsetsListener;)V
at
android.support.design.internal.ScrimInsetsFrameLayout.<init>(ScrimInsetsFrameLayout.java:61)
at
android.support.design.widget.NavigationView.<init>(NavigationView.java:99)
at
android.support.design.widget.NavigationView.<init>(NavigationView.java:95)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native
Method)   at
 sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
 at
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at
org.jetbrains.android.uipreview.ViewLoader.createNewInstance(ViewLoader.java:465)
at
org.jetbrains.android.uipreview.ViewLoader.loadClass(ViewLoader.java:172)
at
org.jetbrains.android.uipreview.ViewLoader.loadView(ViewLoader.java:105)
at
com.android.tools.idea.rendering.LayoutlibCallbackImpl.loadView(LayoutlibCallbackImpl.java:186)
at
android.view.BridgeInflater.loadCustomView(BridgeInflater.java:334)
at
android.view.BridgeInflater.loadCustomView(BridgeInflater.java:345)
at
android.view.BridgeInflater.createViewFromTag(BridgeInflater.java:245)
at
android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727)
at
android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:858)
at
 android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:70)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:834)  at
android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821)
 at android.view.LayoutInflater.inflate(LayoutInflater.java:518)

here is my gradle file attached. Please have a look at it.

2条回答
一夜七次
2楼-- · 2019-08-01 17:53

The answer to my question was given by @Piyush. The two dependencies were clashing I guess. so in short the answer to my issue will be if you are using

 compile 'com.android.support:appcompat-v7:24.+'

etc.

then DO NOT USE

compile 'com.google.android:support-v4:r7'

along with it.

查看更多
Fickle 薄情
3楼-- · 2019-08-01 18:04

Change your app compat gradle as like below

compile 'com.android.support:appcompat-v7:23.4.0'

don't use gradle with +

compile 'com.android.support:appcompat-v7:23.+'

Hope this helps..!!

查看更多
登录 后发表回答