gpt4 book ai didi

android - 使用 HTTP AsyncTask 登录

转载 作者:太空宇宙 更新时间:2023-11-03 10:43:01 24 4
gpt4 key购买 nike

我一直在与 AsyncTask 作斗争。我找不到错误。我不明白为什么 AsyncTask 不起作用,尽管我在这里只有 String 和 Boolean。请帮助。谢谢你。

onPostExecute 部分的错误是:

The method did not override method from its superclass.

    public class UserLoginTask extends AsyncTask<String, String, String> {

private final String mEmail;
private final String mPassword;

UserLoginTask(String email, String password) {
mEmail = email;
mPassword = password;
}

@Override
protected String doInBackground(String... arg0) {
try{
for (String credential : DUMMY_CREDENTIALS) {
String[] pieces = credential.split(":");
if (pieces[0].equals(mEmail) && pieces[1].equals(mPassword)) {
// Account exists, return true if the password matches.
pieces[0]=arg0[0];
pieces[1]=arg0[1];
}
}
String username = (String)arg0[0];
String password = (String)arg0[1];
Log.i("Username", username);
Log.i("Password", password);
String link="http://";
Log.i("link", link);

// Prep HTTP for use
HttpClient client=new DefaultHttpClient();
HttpPost post = new HttpPost(link);

// Prep data for sending to server
List<NameValuePair> pairs = new ArrayList<NameValuePair>();
pairs.add(new BasicNameValuePair("username", username));
pairs.add(new BasicNameValuePair("password", password));
post.setEntity(new UrlEncodedFormEntity(pairs));

// Send data to server
HttpResponse response = client.execute(post);

String responseText = null;

// Time to evaluate how server reacted
try {
// try to get server response
responseText = EntityUtils.toString(response.getEntity());
Log.i("Server Response: ", responseText);
}
catch (Exception e) {
// Failed to get server response, log why it failed.
e.printStackTrace();
Log.i("Parse Exception", e + "");
}
return responseText;
}
catch(Exception e){
Log.i("exception", "error");
return new String("Exception: " + e.getMessage());
}
}

@Override
protected void onPostExecute(final boolean success) {
mAuthTask = null;
finish();
if (success) {
finish();
Intent myIntent = new Intent(membership.this, membership_memberonly.class);
membership.this.startActivity(myIntent);
} else {
mPasswordView.setError(getString(R.string.error_incorrect_password));
mPasswordView.requestFocus();
}
}

@Override
protected void onCancelled() {
mAuthTask = null;
}
}

最佳答案

那么,您有 2 个 doInBackground 方法。只有其中一个应该存在。

关于android - 使用 HTTP AsyncTask 登录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30338201/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com