0

我正在尝试使用 SSO 并在某些文本上使用 onClickListener 更新我的状态,当我单击 post_badge_text 时,我收到一个未实现的接口处理程序错误。

这是该课程的来源。

import com.facebook.android.BaseDialogListener;
import com.facebook.android.Facebook;
import com.facebook.android.R;
import com.facebook.android.Utility;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.facebook.android.Facebook.*;


public class SocialSharing extends Activity{

private static final String APP_ID = "286529654765268";
//private static final String[] PERMISSIONS = new String[] {"publish_stream"};
private static final String TOKEN = "access_token";
private static final String EXPIRES = "expires_in";
private static final String KEY = "facebook-credentials";
private Facebook facebook = new Facebook(APP_ID);
private EditText edittext;
private ImageView badge;
private TextView post_badge_text;
private TextView update_status_text;
private TextView post_achievement_text;
private TextView tweet_badge_text;
private TextView invite_friends_text;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.socialsharing);

    //Make references to all our views
    edittext = (EditText) findViewById(R.id.edittext);
    badge = (ImageView) findViewById(R.id.badge);
    post_badge_text = (TextView) findViewById(R.id.post_badge_text);
    update_status_text = (TextView) findViewById(R.id.update_status_text);
    post_achievement_text = (TextView) findViewById(R.id.post_achievement_text);
    tweet_badge_text = (TextView) findViewById(R.id.tweet_badge_text);
    invite_friends_text = (TextView) findViewById(R.id.invite_friends_text);


    if(restore(facebook, getApplicationContext())){
    //authorize the user. 
    facebook.authorize(this, new DialogListener() {
        @Override
        public void onComplete(Bundle values) {
            Toast.makeText(getApplicationContext(), "Successfully Logged In to facebook!", Toast.LENGTH_LONG).show();
        }

        @Override
        public void onCancel() {}

        @Override
        public void onFacebookError(com.facebook.android.FacebookError e) {
            e.printStackTrace();
                        if(facebook.isSessionValid()){
                Toast.makeText(getApplicationContext(), "Successfully Logged in to Facebook!", Toast.LENGTH_LONG).show();
            }
            else{
                Log.e("FACEBOOK FAIL", "Facebook has epicly failed with an error in onCreate in Social Sharing or you are logged in already");
            }
        }

        @Override
        public void onError(com.facebook.android.DialogError e) {
            // TODO Auto-generated method stub

        }
    });
    } else { save(facebook, getApplicationContext()); }

    /*
     * callback for the feed dialog which updates the profile status
     */
    class UpdateStatusListener extends BaseDialogListener {

        public void onComplete(Bundle values) {
            final String postId = values.getString("post_id");
            if (postId != null) {
                new UpdateStatusResultDialog(SocialSharing.this, "Update Status executed", values)
                        .show();
            } else {
                Toast toast = Toast.makeText(getApplicationContext(), "No wall post made",
                        Toast.LENGTH_SHORT);
                toast.show();
            }
        }
    }

    //check for clicks
    post_badge_text.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
             Bundle params = new Bundle();
             params.putString("caption", getString(R.string.app_name));
             params.putString("description", getString(R.string.app_desc));
             params.putString("picture", Utility.HACK_ICON_URL);
             params.putString("name", getString(R.string.app_action));

             Utility.mFacebook.dialog(SocialSharing.this, "feed", params, new UpdateStatusListener());
             String access_token = Utility.mFacebook.getAccessToken();
             Log.e("accessToken", "access Token is " + access_token);
             System.out.println(access_token);


        }
    });

}

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

    facebook.authorizeCallback(requestCode, resultCode, data);
}

/*
 * Save the access token and expiry date so you don't have to fetch it each
 * time
 */

public static boolean save(Facebook session, Context context) {
    Editor editor = context.getSharedPreferences(KEY, Context.MODE_PRIVATE).edit();
    editor.putString(TOKEN, session.getAccessToken());
    editor.putLong(EXPIRES, session.getAccessExpires());
    return editor.commit();
}

/*
 * Restore the access token and the expiry date from the shared preferences.
 */
public static boolean restore(Facebook session, Context context) {
    SharedPreferences savedSession = context.getSharedPreferences(KEY, Context.MODE_PRIVATE);
    session.setAccessToken(savedSession.getString(TOKEN, null));
    session.setAccessExpires(savedSession.getLong(EXPIRES, 0));
    return session.isSessionValid();
}


}

这是我得到的错误:

05-09 12:31:22.300: E/Handler(12860): Failed to handle callback; interface not implemented, callback:android.view.View$PerformClick@40d37250
05-09 12:31:22.300: E/Handler(12860): java.lang.NullPointerException
05-09 12:31:22.300: E/Handler(12860):   at org.jujitsu.app.com.SocialSharing$2.onClick(SocialSharing.java:114)
05-09 12:31:22.300: E/Handler(12860):   at android.view.View.performClick(View.java:3538)
05-09 12:31:22.300: E/Handler(12860):   at android.view.View$PerformClick.run(View.java:14330)
05-09 12:31:22.300: E/Handler(12860):   at android.os.Handler.handleCallback(Handler.java:607)
05-09 12:31:22.300: E/Handler(12860):   at android.os.Handler.dispatchMessage(Handler.java:92)
05-09 12:31:22.300: E/Handler(12860):   at android.os.Looper.loop(Looper.java:154)
05-09 12:31:22.300: E/Handler(12860):   at android.app.ActivityThread.main(ActivityThread.java:4974)
05-09 12:31:22.300: E/Handler(12860):   at java.lang.reflect.Method.invokeNative(Native Method)
05-09 12:31:22.300: E/Handler(12860):   at java.lang.reflect.Method.invoke(Method.java:511)
05-09 12:31:22.300: E/Handler(12860):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
05-09 12:31:22.300: E/Handler(12860):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
05-09 12:31:22.300: E/Handler(12860):   at dalvik.system.NativeStart.main(Native Method)

我真的被这个错误困住了......任何帮助都会很棒。谢谢!

4

1 回答 1

0

它现在固定了。这是我的代码中的一个小错误,我没有注意到。出于某种原因,一个覆盖在类中而不是方法中。

于 2012-05-14T14:02:49.627 回答