Search code examples
androidfacebook-likefacebook-android-sdk

Exception in Facebook Like button for android apps


I have setup correctly the facebook SDK for facebook like button. It works fine on one phone (Android 4.3) but gives an exception on the other (Android 4.4.4)

The exception is as:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.compzets.popopics/com.compzets.popopics.ui.MainPagerActivity}: android.view.InflateException: Binary XML file line #80: Error inflating class com.facebook.widget.LikeView
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2212)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2271)
    at android.app.ActivityThread.access$800(ActivityThread.java:144)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1205)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:136)
    at android.app.ActivityThread.main(ActivityThread.java:5146)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:732)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:566)
    at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #80: Error inflating class com.facebook.widget.LikeView
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:707)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
    at android.support.v7.app.ActionBarActivityDelegateBase.setContentView(ActionBarActivityDelegateBase.java:228)
    at android.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:102)
    at com.compzets.popopics.ui.MainPagerActivity.onCreate(MainPagerActivity.java:58)
    at android.app.Activity.performCreate(Activity.java:5231)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2169)
    ... 11 more
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.facebook.widget.LikeView" on path: DexPathList[[zip file "/data/app/com.compzets.popopics-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.compzets.popopics-1, /vendor/lib, /system/lib]]
    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
    at android.view.LayoutInflater.createView(LayoutInflater.java:559)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)
    ... 22 more

It gives a ClassNotFoundException, I have no clue as to why it happens? And if there is an issue then why it isn't reflected on both phones.


Solution

  • I faced a similar issue some days back and the following solved it:

    1. Removed compile 'com.facebook.android:facebook-android-sdk:3.21.1' from the dependencies in gradle
    2. Synced it
    3. Added the same dependency again
    4. Again Synced it

    Hope this works for you as well!