Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facebook Android SDK source will not compile with Eclipse Indigo

After finally getting the Android Facebook SDK to properly import thanks to this, I found that eclipse does not recognize the override of onclick in FbDialog.java:

mCrossImage.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        mListener.onCancel();
        FbDialog.this.dismiss();
    }
});

Nor does it recognize the overrides of onServiceConnected and onServiceDisconnected in the TokenRefreshServiceConnection implementation of ServiceConnection

@Override
public void onServiceConnected(ComponentName className, IBinder service) {
    messageSender = new Messenger(service);
    refreshToken();
}

@Override
public void onServiceDisconnected(ComponentName arg) {
    serviceListener.onError(new Error("Service disconnected"));
    // We returned an error so there's no point in
    // keeping the binding open.
    mAuthActivity.unbindService(TokenRefreshServiceConnection.this);
}

All three methods say, in the warning, that the method must override a superclass method. I have not modified the code at all yet. I checked that Eclipse recognizes the types as the same ones in the respective superclasses, and I have tried pressing control-shift-o to organize the imports, which was a fix suggested in this answer for a similar problem.

These overrides are part of the SDK, not any separate project. I set up the project to use Android SDK 2.2 as was shown on Facebook's instructions, and 4.0.3, which should be, theoretically, compatible with all previous versions. I have yet to get Facebook's own code to work. As a side note, is there a jar I can use instead? It would make this much easier.

like image 600
Poik Avatar asked Feb 07 '12 02:02

Poik


2 Answers

Guessing your Project Properties -> Java Compiler Compiler compliance level is set to 1.5, not 1.6 (or higher).

Change this.

Why is javac failing on @Override annotation

like image 145
Sean Avatar answered Oct 05 '22 00:10

Sean


The lazy, fast and easy fix is to remove the @Override annotations. The correct fix is to check that the project compiles to Java 1.5 or above, to use "fix project properties" from Eclipse, and possibly to check that the Facebook library project uses the same Android SDK for compiling against, as your project.

like image 31
zrgiu Avatar answered Oct 05 '22 02:10

zrgiu