0
我有一些asynstask是在我的主要活動中定義的。我試圖通過將這些類中的每一個放在單獨的文件中來使代碼更加模塊化。不幸的是,我不斷收到一些錯誤,例如無法獲得工作意圖。如何將此代碼與我的主要活動連接起來。順便說一句,如果我把這個代碼原樣(沒有導入)在mainActivity它工作得很好。謝謝如何將每個AsyncTask類放在一個單獨的文件中?
package com.example.food4thought;
import java.net.URL;
import twitter4j.TwitterException;
import twitter4j.auth.RequestToken;
import android.content.Intent;
import android.net.Uri;
import android.os.AsyncTask;
import android.util.Log;
import android.widget.Toast;
// Starts an intent that loads up a web browser and asks the user to log in to twitter
// and get a pin#
public class TwitterLogin extends AsyncTask<URL, Integer, RequestToken> {
protected RequestToken doInBackground(URL... arg0) {
try {
requestToken = twitter.getOAuthRequestToken();
Log.i("Got Request Token", "food4thought");
} catch (TwitterException e) {
Log.i("Failed to get Request Token", "food4thought");
}
//Log.i(requestToken.getAuthorizationURL(), "food4thought");
//requestToken.getAuthorizationURL();
//log_in.setText();
try {
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(requestToken.getAuthorizationURL()));
startActivity(browserIntent);
}
catch(NullPointerException e) {
runOnUiThread(new Runnable() {
public void run() {
Toast.makeText(getApplicationContext(), "Unable to log in, No access to the Internet.", Toast.LENGTH_LONG).show();
}
});
}
return null;
}
}
你可以添加「一些錯誤」部分來解決你的問題嗎? –
另外,請注意您的編譯錯誤。如果你明白髮生了什麼,你可以解決錯誤。 –