【发布时间】:2016-01-31 00:24:24
【问题描述】:
我查看了其他线程,但它们对我完全没有用。
我是 Java 和 Android 开发的新手。我正在尝试为我的 Android 应用程序登录,所以我试图按照在线教程进行操作,然后按照我希望的方式对其进行调整。所以我在整个项目中都遇到了错误,它们都是关于同一件事的。在网站上它说它工作正常,所以我不知道我在做什么。
所以,现在解决错误!
- “NetCheck”类必须声明为抽象或在“AsyncTask”中实现抽象方法“doInBackground(params...)”
Netcheck 类中的@Override(除了 onPreExecute 之外的所有)都会出现此错误:方法不会覆盖超类中的方法
类“ProcessRegister”必须声明为抽象或在“AsyncTask”中实现抽象方法“doInBackground(params....)”
ProcessRegister 类中的@Overide 给出错误:方法不覆盖超类中的方法。除了 onPreExecute 之外,所有 @overrides 都会出错。
查看其他帖子后,它说要确保方法是公开的或受保护的。他们是哪个,另一个说要检查拼写。一切对我来说都很好,除非我错过了什么。有人可以给我一些帮助吗!谢谢!!
import android.app.Activity;
import android.app.PendingIntent;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.drm.ProcessedData;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import wishlist.com.gimme.library.UserFunctions;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
public class PasswordReset extends Activity {
private static String KEY_SUCCESS = "success";
private static String KEY_ERROR = "error";
EditText email;
TextView alert;
Button resetpass;
/**
* Called when the activity is first created.
*/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.passwordreset);
Button login = (Button) findViewById(R.id.bktolog);
login.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent myIntent = new Intent(view.getContext(), Login.class);
startActivityForResult(myIntent, 0);
finish();
}
});
email = (EditText) findViewById(R.id.forpas);
alert = (TextView) findViewById(R.id.alert);
resetpass = (Button) findViewById(R.id.respass);
resetpass.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
NetAsync(view);
}
});}
private class NetCheck extends AsyncTask
{
private ProgressDialog nDialog;
@Override
protected void onPreExecute(){
super.onPreExecute();
nDialog = new ProgressDialog(PasswordReset.this);
nDialog.setMessage("Loading..");
nDialog.setTitle("Checking Network");
nDialog.setIndeterminate(false);
nDialog.setCancelable(true);
nDialog.show();
}
@Override
protected Boolean doInBackground(String... args){
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo netInfo = cm.getActiveNetworkInfo();
if (netInfo != null && netInfo.isConnected()) {
try {
URL url = new URL("http://www.google.com");
HttpURLConnection urlc = (HttpURLConnection) url.openConnection();
urlc.setConnectTimeout(3000);
urlc.connect();
if (urlc.getResponseCode() == 200) {
return true;
}
} catch (MalformedURLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return false;
}
@Override
protected void onPostExecute(Boolean th){
if(th == true){
nDialog.dismiss();
new ProcessRegister().execute();
}
else{
nDialog.dismiss();
alert.setText("Error in Network Connection");
}
}
}
protected class ProcessRegister extends AsyncTask {
private ProgressDialog pDialog;
String forgotpassword;
@Override
protected void onPreExecute() {
super.onPreExecute();
forgotpassword = email.getText().toString();
pDialog = new ProgressDialog(PasswordReset.this);
pDialog.setTitle("Contacting Servers");
pDialog.setMessage("Getting Data ...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(true);
pDialog.show();
}
@Override
protected JSONObject doInBackground(String... args) {
UserFunctions userFunction = new UserFunctions();
JSONObject json = userFunction.forPass(forgotpassword);
return json;
}
protected void onProgressUpdate(Integer... args) {
}
@Override
protected void onPostExecute(JSONObject json) {
/**
* Checks if the Password Change Process is sucesss
**/
try {
if (json.getString(KEY_SUCCESS) != null) {
alert.setText("");
String res = json.getString(KEY_SUCCESS);
String red = json.getString(KEY_ERROR);
if(Integer.parseInt(res) == 1){
pDialog.dismiss();
alert.setText("A recovery email is sent to you, see it for more details.");
}
else if (Integer.parseInt(red) == 2)
{ pDialog.dismiss();
alert.setText("Your email does not exist in our database.");
}
else {
pDialog.dismiss();
alert.setText("Error occured in changing Password");
}
}}
catch (JSONException e) {
e.printStackTrace();
}
}}
public void NetAsync(View view){
new NetCheck().execute();
}
}
【问题讨论】:
-
您的
AsyncTask需要看起来像这样,取决于您需要或在做什么:AsyncTask<String, Integer, Boolean> -
如果您有其他问题,请提出新问题。不要试图将一个问题变成另一个问题。