我正在關注我在本網站上找到的教程http://www.helloandroid.com/tutorials/using-facebook-sdk-android-development-part-2,並且當我在類中插入了2組代碼段時,教程指定了我得到4個facebook sdk相關錯誤。我將代碼段插入到粗體/星號錯誤的代碼段中。Facebook Android SDK問題
有沒有人有任何想法我可以修復這些錯誤?
下面是錯誤消息我得到當我將鼠標放在錯誤,依次是:
1.onCreate(捆綁savedInstanceState):主要類型的方法的onCreate(束)必須覆蓋或實現超類型方法
btnLogin.setOnClickListener(新OnClickListener():OnClickListener不能被解析爲一個類型
LoginDialogListener:類型FBConnectionActivity.LoginDialogListener必須實現繼承ABST RACT方法Facebook.DialogListener.onComplete(束)
的onComplete(束值):類型FBConnectionActivity.LoginDialogListener的方法的onComplete(束)必須重寫或實現的超類型方法
段1(2錯誤): 在這部分中的錯誤是在OnCreate中和onclicklistener
package com.outfit.first;
import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.TextView;
public class main extends FBConnectionActivity {
private TextView txtUserName;
private ProgressBar pbLogin;
private Button btnLogin;
@Override
public void **onCreate(Bundle savedInstanceState)** {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
txtUserName = (TextView) findViewById(R.id.textFacebook);
pbLogin = (ProgressBar) findViewById(R.id.progressLogin);
btnLogin = (Button) findViewById(R.id.buttonLogin);
btnLogin.setOnClickListener(new **OnClickListener**() {
@Override
public void onClick(View arg0) {
pbLogin.setVisibility(ProgressBar.VISIBLE);
setConnection();
getID(txtUserName, pbLogin);
}
});
}
}
段2(2錯誤):在這一部分中的錯誤是在LoginDialogListener類和的onComplete(外灘le值)在該類內。
package com.outfit.first;
import com.facebook.android.AsyncFacebookRunner;
import com.facebook.android.Facebook;
import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.util.Log;
import android.widget.ProgressBar;
import android.widget.TextView;
public abstract class FBConnectionActivity extends Activity {
public static final String TAG = "FACEBOOK";
private Facebook mFacebook;
public static final String APP_ID = "136907069717004";
private AsyncFacebookRunner mAsyncRunner;
private static final String[] PERMS = new String[] { "read_stream" };
private SharedPreferences sharedPrefs;
private Context mContext;
private TextView username;
private ProgressBar pb;
public void setConnection() {
mContext = this;
mFacebook = new Facebook(APP_ID);
mAsyncRunner = new AsyncFacebookRunner(mFacebook);
}
public void getID(TextView txtUserName, ProgressBar progbar) {
username = txtUserName;
pb = progbar;
if (isSession()) {
Log.d(TAG, "sessionValid");
mAsyncRunner.**request**("me", new IDRequestListener());
} else {
// no logged in, so relogin
Log.d(TAG, "sessionNOTValid, relogin");
mFacebook.**authorize**(this, PERMS, new LoginDialogListener());
}
}
public boolean isSession() {
sharedPrefs = PreferenceManager.getDefaultSharedPreferences(mContext);
String access_token = sharedPrefs.getString("access_token", "x");
Long expires = sharedPrefs.getLong("access_expires", -1);
Log.d(TAG, access_token);
if (access_token != null && expires != -1) {
mFacebook.setAccessToken(access_token);
mFacebook.setAccessExpires(expires);
}
return mFacebook.isSessionValid();
}
private class **LoginDialogListener** implements DialogListener {
@Override
public void **onComplete(Bundle values)** {
Log.d(TAG, "LoginONComplete");
String token = mFacebook.getAccessToken();
long token_expires = mFacebook.getAccessExpires();
Log.d(TAG, "AccessToken: " + token);
Log.d(TAG, "AccessExpires: " + token_expires);
sharedPrefs = PreferenceManager
.getDefaultSharedPreferences(mContext);
sharedPrefs.edit().putLong("access_expires", token_expires)
.commit();
sharedPrefs.edit().putString("access_token", token).commit();
mAsyncRunner.request("me", new IDRequestListener());
}
@Override
public void onFacebookError(FacebookError e) {
Log.d(TAG, "FacebookError: " + e.getMessage());
}
@Override
public void onError(DialogError e) {
Log.d(TAG, "Error: " + e.getMessage());
}
@Override
public void onCancel() {
Log.d(TAG, "OnCancel");
}
}
private class IDRequestListener implements RequestListener {
@Override
public void onComplete(String response, Object state) {
try {
Log.d(TAG, "IDRequestONComplete";);
Log.d(TAG, "Response: " + response.toString());
JSONObject json = Util.parseJson(response);
final String id = json.getString("id");
final String name = json.getString("name");
FBConnectionActivity.this.runOnUiThread(new Runnable() {
public void run() {
username.setText("Welcome: " + name+"\n ID: "+id);
pb.setVisibility(ProgressBar.GONE);
}
});
} catch (JSONException e) {
Log.d(TAG, "JSONException: " + e.getMessage());
} catch (FacebookError e) {
Log.d(TAG, "FacebookError: " + e.getMessage());
}
}
@Override
public void onIOException(IOException e, Object state) {
Log.d(TAG, "IOException: " + e.getMessage());
}
@Override
public void onFileNotFoundException(FileNotFoundException e,
Object state) {
Log.d(TAG, "FileNotFoundException: " + e.getMessage());
}
@Override
public void onMalformedURLException(MalformedURLException e,
Object state) {
Log.d(TAG, "MalformedURLException: " + e.getMessage());
}
@Override
public void onFacebookError(FacebookError e, Object state) {
Log.d(TAG, "FacebookError: " + e.getMessage());
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
mFacebook.authorizeCallback(requestCode, resultCode, data);
}
}
你可以顯示logcat,以便我們可以看到錯誤說什麼? – IamAlexAlright
嗯當然。雖然我從來沒有嘗試過運行該程序,但是當我編寫代碼時,發現eclipse中的錯誤。 – Peter
噢,當你將鼠標放在有問題的代碼上時,它會說什麼? – IamAlexAlright