1

I have been trying to add a facebook like button into my Android App. I followed everything from the facebook developers site including from installing facebook-sdk to following their code. On doing everything I now find a error in my App which I am unable to go through. I searched through a number of resources for solutions but could never get a working one.

This is how i implemented it. The codes below represent my MainActivity.java

import com.facebook.UiLifecycleHelper;
import com.facebook.widget.LikeView;

public class MainActivity extends Activity {
  private UiLifecycleHelper uiHelper;

  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    uiHelper = new UiLifecycleHelper(this, callback);

    LikeView likeView = (LikeView) findViewById(R.id.like_view);
    likeView.setObjectId("https://www.facebook.com/NewsNrnDotCom");
  .
  .
  .

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

    uiHelper.onActivityResult(requestCode, resultCode, data, null);
 }
}

And the codes for the file activity_main.xml is

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

    <LikeView
        android:id="@+id/like_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" /> 

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="100dp"
        android:contentDescription="@string/logo"
        android:padding="10dp"
        android:src="@drawable/nrnlogo" />
</LinearLayout>
</LinearLayout>

Everything is fine but with the code

  uiHelper = new UiLifecycleHelper(this, callback);

There is an error message which says:

"callback cannot be resolved to a variable"

I am unable to find where did I make an error. I have here added just the few related code so as to prevent looking bulky. I can add any more code if needed.

bh.amir
  • 109
  • 2
  • 15

2 Answers2

2

You must declare what callback means.

private Session.StatusCallback callback = new Session.StatusCallback() {
    @Override
    public void call(Session session, SessionState state,
            Exception exception) {
        onSessionStateChange(session, state, exception);
    }
};

However, as your code looks like, it might lead to another errors. Please check out this question to avoid more issues.

Community
  • 1
  • 1
Machado
  • 14,105
  • 13
  • 56
  • 97
0

I think you missing to declare Session.StatusCallback in your activity :

private Session.StatusCallback callback = new Session.StatusCallback() {
    @Override
    public void call(Session session, SessionState state, Exception exception) {
        onSessionStateChange(session, state, exception);
    }
};
Haresh Chhelana
  • 24,720
  • 5
  • 57
  • 67