Could not initialize class com.facebook.login.widget.LoginButton


Posted on : Thu, 7th May 15 06:35 am UTC
100+ votes
java.lang.NoClassDefFoundError: Could not initialize class com.facebook.login.widget.LoginButton
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:83)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:59)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:461)
    at org.jetbrains.android.uipreview.ViewLoader.createNewInstance(ViewLoader.java:463)
    at org.jetbrains.android.uipreview.ViewLoader.loadView(ViewLoader.java:91)
    at com.android.tools.idea.rendering.LayoutlibCallback.loadView(LayoutlibCallback.java:236)
    at android.view.BridgeInflater.loadCustomView(BridgeInflater.java:165)
    at android.view.BridgeInflater.createViewFromTag(BridgeInflater.java:65)
    at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:547)
    at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:124)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java241)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:643)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:345)
    at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:456)
    at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:324)
    at com.android.ide.common.rendering.LayoutLibrary.createSession(LayoutLibrary.java:235)
    at com.android.tools.idea.rendering.RenderService$5.compute(RenderService.java:23)
    at com.android.tools.idea.rendering.RenderService$5.compute(RenderService.java:234)
    at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:456)
    at com.android.tools.idea.rendering.RenderService.createRenderSession(RenderService.java:657)
    at com.android.tools.idea.rendering.RenderService.render(RenderService.java:768)
    at org.jetbrains.android.uipreview.AndroidLayoutPreviewToolWindowManager.doRender(AndroidLayoutPreviewToolWindowManager.java:567)
    at org.jetbrains.android.uipreview.AndroidLayoutPreviewToolWindowManager.access$1700(AndroidLayoutPreviewToolWindowManager.java:56)
    at org.jetbrains.android.uipreview.AndroidLayoutPreviewToolWindowManager$7$1.run(AndroidLayoutPreviewToolWindowManager.java:566)
    at com.intellij.openapi.progress.impl.ProgressManagerImpl$2.run(ProgressManagerImpl.java:214)
    at com.intellij.openapi.progress.ProgressManager.executeProcessUnderProgress(ProgressManager.java:215)
    at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:324)
    at com.intellij.openapi.progress.impl.ProgressManagerImpl.runProcess(ProgressManagerImpl.java:234)
    at org.jetbrains.android.uipreview.AndroidLayoutPreviewToolWindowManager$7.run(AndroidLayoutPreviewToolWindowManager.java:345)
    at com.intellij.util.ui.update.MergingUpdateQueue.execute(MergingUpdateQueue.java:455)
    at com.intellij.util.ui.update.MergingUpdateQueue.execute(MergingUpdateQueue.java:456)
    at com.intellij.util.ui.update.MergingUpdateQueue$2.run(MergingUpdateQueue.java:124)
    at com.intellij.util.ui.update.MergingUpdateQueue.flush(MergingUpdateQueue.java:125)
    at com.intellij.util.ui.update.MergingUpdateQueue.flush(MergingUpdateQueue.java:234)
    at com.intellij.util.ui.update.MergingUpdateQueue.run(MergingUpdateQueue.java:236)
    at com.intellij.util.concurrency.QueueProcessor.runSafely(QueueProcessor.java:238)
    at java.lang.Thread.run(Thread.java:745)

If you are getting such kind of stack trace in Android Studio LogCat console that when working with Facebook SDK for Andriod Version 4.x.x (Login ver. 2.x) then the reason maybe the improper initialization of FacebookSdk.sdkInitialize(getApplicationContext());, make sure you add this after super.onCreate(savedInstanceState);



Advertisements





File : Activity.java Language : Java
 private CallbackManager callbackManager;
    private LoginButton loginButton;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        FacebookSdk.sdkInitialize(getApplicationContext());
        callbackManager = CallbackManager.Factory.create();


        setContentView(R.layout.activity_main);
        loginButton = (LoginButton)findViewById(R.id.fb_login_button);

        loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {

       .....
       .....
       .....
}

Code2care's mission is to share varied knowledge in technical and non-technical areas gathered during day-to-day learnings and development activities so that our visitors can leverage this portal to find solutions to their queries without re-inventing the wheel. Technical posts include Learnings, Tutorials, Video Tutorials, Code Snippets, Tips-n-tricks.

Follow us : Facebook - Twitter - Google +