Android Studio 1.1.0 Facebook SDK登录 [英] Android Studio 1.1.0 Facebook SDK Login

查看:158
本文介绍了Android Studio 1.1.0 Facebook SDK登录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



所以我添加了 compile'c​​om.facebook.android:facebook-android- sdk:4.0.0'



然后添加 FacebookSdk.sdkInitialize(getApplicationContext());
到MainActivity.java



但是当我添加

 < com.facebook.login.widget.LoginButton 
android:id =@ + id / login_button
android:layout_width =wrap_content
android:layout_height =wrap_content
android:layout_gravity =center_horizo​​ntal
android:layout_marginTop =30dp
android:layout_marginBottom =30dp/>`

我有以下错误




com.facebook.login.widget.LoginButton(打开类,显示异常)
提示:使用视图.isInEditMode()在您的自定义视图中跳过代码或显示示例数据显示在IDE
异常详细信息java.lang.NoClassDefFoundError:无法初始化类com.facebook.login.widget.LoginButton
在java.lang.reflect.Constructor.newInstance(Constructor.java: 422)
在android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:806)
在android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:64)
在android.view.LayoutInflater .rInflate(LayoutInflater.java:782)
在android.view.LayoutInflater.inflate(LayoutInflater.java:504)
在android.view.LayoutInflater.inflate(LayoutInflater.java:385)将堆栈复制到剪贴板


解决方案

您没有发布您的活动代码。但我认为你的代码就像:

  setContentView(R.layout.my_login_layout); 
FacebookSdk.sdkInitialize(getApplicationContext());
mCallbackManager = CallbackManager.Factory.create();

问题是代码的顺序。忽略布局中的渲染问题,将代码的顺序更改为:

  FacebookSdk.sdkInitialize(getApplicationContext() ); 
mCallbackManager = CallbackManager.Factory.create(); //这行不重要
setContentView(R.layout.my_login_layout);

在OnCreate(...)中使用此代码{...}



避免布局渲染问题



如果要解决渲染问题(布局预览) a href =https://stackoverflow.com/questions/29268738/android-studio-1-1-0-facebook-sdk-login/29354870#29354870> @ Nathan30 answer (见下文)。


  1. 下载Facebook SDK

  2. 将其作为模块导入到您的项目

  3. 然后在您的布局中添加< com.facebook.widget.LoginButton ... />


I try to test the login with facebook SDK.

So I add with compile 'com.facebook.android:facebook-android-sdk:4.0.0'.

Then add FacebookSdk.sdkInitialize(getApplicationContext()); to MainActivity.java

But when I add

 <com.facebook.login.widget.LoginButton
    android:id="@+id/login_button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal"
    android:layout_marginTop="30dp"
    android:layout_marginBottom="30dp" />`

I have this following error :

Rendering Problems The following classes could not be instantiated:
com.facebook.login.widget.LoginButton (Open Class, Show Exception)
Tip: Use View.isInEditMode() in your custom views to skip code or show sample data when shown in the IDE  
Exception Details java.lang.NoClassDefFoundError: Could not initialize class com.facebook.login.widget.LoginButton
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:806)
at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:64)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:782)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:385) Copy stack to clipboard

解决方案

You didn't posted your Activity code. But i think your code is like:

setContentView(R.layout.my_login_layout);
FacebookSdk.sdkInitialize(getApplicationContext());
mCallbackManager = CallbackManager.Factory.create();

The problem is the order of the code. Ignore the "Render problems" in the layout, change the order of the code to this:

FacebookSdk.sdkInitialize(getApplicationContext());
mCallbackManager = CallbackManager.Factory.create(); // this line doesn't matter 
setContentView(R.layout.my_login_layout);

Use this code in OnCreate(...) { ... }

Avoid layout render problems

if you want to solve the render problems (layout preview) check the @Nathan30 answer (see below).

  1. Download Facebook SDK
  2. Import it as a Module to your project
  3. Then add <com.facebook.widget.LoginButton .../> to your layout.

这篇关于Android Studio 1.1.0 Facebook SDK登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆