无法解析符号callbackManager facebook sdk 4.0的lib

时间:2016-06-26 17:55:57

标签: java android facebook

我正在使用facebook登录API注册我的应用程序。现在我在callbackManager函数上出错了。它说无法解析符号callbackManager。有人可以在这方面帮助我。

这是我的xml。

 <?xml version="1.0" encoding="utf-8"?>
 <android.support.constraint.ConstraintLayout
 xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:app="http://schemas.android.com/apk/res-auto"
 xmlns:tools="http://schemas.android.com/tools"
 android:id="@+id/activity_main"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:background="#5b9bd5"
 tools:context="com.example.ratingapp.ratingapp.MainActivity">

    <ImageButton
    android:id="@+id/regiterbutton"
    android:layout_width="191dp"
    android:layout_height="56dp"
    android:background="@drawable/registerbutton"

    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    app:layout_constraintTop_toTopOf="@+id/activity_main"
    app:layout_constraintRight_toRightOf="@+id/loginbutton"
    app:layout_constraintBottom_toBottomOf="@+id/activity_main"
    app:layout_constraintVertical_bias="0.83" />

    <ImageButton
    android:id="@+id/loginbutton"
    android:layout_width="191dp"
    android:layout_height="0dp"
    android:background="@drawable/loginbutton"
    android:layout_above="@+id/regiterbutton"
    app:layout_constraintLeft_toLeftOf="@+id/activity_main"
    tools:layout_constraintLeft_creator="1"
    app:layout_constraintRight_toRightOf="@+id/activity_main"
    tools:layout_constraintRight_creator="1"
    app:layout_constraintBottom_toTopOf="@+id/regiterbutton"
    android:layout_marginBottom="32dp" />
   </android.support.constraint.ConstraintLayout>

这是我的MainActivity.java

package com.example.ratingapp.ratingapp;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ImageButton;
import android.widget.Toast;
import com.facebook.CallbackManager;
import com.facebook.FacebookCallback;
import com.facebook.FacebookException;
import com.facebook.FacebookSdk;
import com.facebook.accountkit.LoginResult;
import com.facebook.login.LoginManager;

import java.util.Arrays;

public class MainActivity extends AppCompatActivity {

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

    FacebookSdk.sdkInitialize(this.getApplicationContext());
    setContentView(R.layout.activity_main);
    callbackManager = CallbackManager.Factory.create();

    LoginManager.getInstance().registerCallback(callbackManager,
            new FacebookCallback<LoginResult>() {
                @Override
                public void onSuccess(LoginResult loginResult) {
                    Log.d("Success", "Login");

                }

                @Override
                public void onCancel() {
                Toast.makeText(MainActivity.this, "Login Cancel",     
   Toast.LENGTH_LONG).show();
                }

                @Override
                public void onError(FacebookException exception) {
                    Toast.makeText(MainActivity.this, 
    exception.getMessage(), Toast.LENGTH_LONG).show();
                }
            });

    setContentView(R.layout.activity_main);

    ImageButton registrationbutton = (ImageButton)  
    findViewById(R.id.regiterbutton);

    registrationbutton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            LoginManager.getInstance().logInWithReadPermissions(this,
     Arrays.asList("public_profile", "user_friends"));
        }
    });

   }

 @Override
 protected void onActivityResult(int requestCode, int resultCode, Intent
 data) {
    super.onActivityResult(requestCode, resultCode, data);

    callbackManager.onActivityResult(requestCode, resultCode, data);
    }
 }

1 个答案:

答案 0 :(得分:1)

你没有定义callBackManager只是像这样全局定义它

public class MainActivity extends AppCompatActivity {
private CallbackManager fbCallback; //define CallbackManager
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FacebookSdk.sdkInitialize(this.getApplicationContext());
setContentView(R.layout.activity_main);
callbackManager = CallbackManager.Factory.create();