我有一個類繼承的AsyncTask接收背景下,字符串的用戶和密碼字符串,如何在Android中執行的AsyncTask - 類埃羅Zygotelnit
我嘗試執行我的AsyncTask,但不工作。
當我執行的AsyncTask類,發生在類Zygotelnit
public void run() {
try {
mMethod.invoke(null, new Object[] { mArgs });
} catch (IllegalAccessException ex) {
throw new RuntimeException(ex);
} catch (InvocationTargetException ex) {
Throwable cause = ex.getCause();
if (cause instanceof RuntimeException) {
throw (RuntimeException) cause;
} else if (cause instanceof Error) {
throw (Error) cause;
}
throw new RuntimeException(ex);
}
}
按照我下面的類,它執行的AsyncTask
mButtonEnter.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
username = mEditTextUser.getText().toString();
password = mEditTextPassword.getText().toString();
new LoginService(LoginActivity.this, username, password).execute();
按照我下面的類AsynTask問題
public class LoginService extends AsyncTask<String, String, String> {
private String username;
private String password;
private Context context;
ProgressDialog progressDialog = new ProgressDialog(context);
public LoginService(Context context, String username, String password){
this.context = context;
this.username = username;
this.password = password;
}
@Override
protected String doInBackground(String... params) {
String result = "";
try {
URL url = new URL("http://192.168.0.11:8080/appoint-api/api/Usuario/doLogin?user=" + this.username + "&senha=" + this.password);
HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
httpURLConnection.setRequestMethod("POST");
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(httpURLConnection.getInputStream()));
String inputLine;
StringBuilder response = new StringBuilder();
while ((inputLine = bufferedReader.readLine()) != null) {
response.append(inputLine);
}
result = response.toString();
bufferedReader.close();
} catch (Exception e) {
Log.d("InputStream", e.getMessage());
}
return result;
}
}
關注日誌中的錯誤Cat
08-16 22:23:29.781 18099-18099/br.com.appoint.android D/AndroidRuntime﹕ Shutting down VM
08-16 22:23:29.781 18099-18099/br.com.appoint.android W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x4108b960)
08-16 22:23:29.875 18099-18099/br.com.appoint.android E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.NullPointerException
at android.app.AlertDialog.resolveDialogTheme(AlertDialog.java:143)
at android.app.AlertDialog.<init>(AlertDialog.java:98)
at android.app.ProgressDialog.<init>(ProgressDialog.java:77)
at br.com.appoint.android.service.LoginService.<init>(LoginService.java:25)
at br.com.appoint.android.activity.LoginActivity$1.onClick(LoginActivity.java:63)
at android.view.View.performClick(View.java:4452)
at android.widget.Button.performClick(Button.java:148)
at android.view.View$PerformClick.run(View.java:18428)
at android.os.Handler.handleCallback(Handler.java:725)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:176)
at android.app.ActivityThread.main(ActivityThread.java:5365)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
at dalvik.system.NativeStart.main(Native Method)
「你知道有什麼問題嗎?」你是否應該告訴我們問題是什麼並尋求解決方案? – e4c5
我的問題是:任務不工作......但我不知道爲什麼asynctask不工作。 –
我想你應該讀這第一個http://stackoverflow.com/help/how-to-ask – e4c5