我需要获取user并将其保存到变量中。
public class MainActivity extends ActionBarActivity
{
User user = new LoginTask2().execute("");
}
class LoginTask2 extends AsyncTask<String, Void, User> {
private Exception exception;
public String hash = "";
protected String doInBackground(String... t) {
RestClient restClient = new HttpRestClient();
restClient.setUserAgent("bot/1.0 by name");
// Connect the user
User user = new User(restClient, "User", "somepass");
try {
user.connect();
//hash = user.getModhash();
return user;
} catch (Exception e) {
e.printStackTrace();
this.exception = e;
return null;
}
}
protected void onPostExecute(String string) {
}
}
它看起来像它的工作,但我不知道如何获得user. 使用此代码,我得到错误:
Error:(49, 47) error: incompatible types
required: String
found: AsyncTask<String,Void,String>
有人可以给我建议如何更改代码吗?