我正在尝试使用AsyncTask(学习),获取致命异常错误 这是电话
String username = usr_number.getText().toString();
String password = password_main.getText().toString();
String[] Loginvalues = {username,password};
new CheckUsername().execute(Loginvalues);
这是班级
public class CheckUsername extends AsyncTask<String[], Integer, String[]>{
@Override
protected String[] doInBackground(String[]... params) {
// TODO Auto-generated method stub
String username = params[0].toString();
String password = params[1].toString();
System.out.println(username);
System.out.println(password);
return null;
}
}
这是我得到的错误
05-09 03:11:04.428: E/AndroidRuntime(1139): FATAL EXCEPTION: AsyncTask #1
05-09 03:11:04.428: E/AndroidRuntime(1139): Process: com.hexwhale.pocketcollege, PID: 1139
05-09 03:11:04.428: E/AndroidRuntime(1139): java.lang.RuntimeException: An error occured while executing doInBackground()
05-09 03:11:04.428: E/AndroidRuntime(1139): at android.os.AsyncTask$3.done(AsyncTask.java:300)
05-09 03:11:04.428: E/AndroidRuntime(1139): at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
05-09 03:11:04.428: E/AndroidRuntime(1139): at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
05-09 03:11:04.428: E/AndroidRuntime(1139): at java.util.concurrent.FutureTask.run(FutureTask.java:242)
05-09 03:11:04.428: E/AndroidRuntime(1139): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
05-09 03:11:04.428: E/AndroidRuntime(1139): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
05-09 03:11:04.428: E/AndroidRuntime(1139): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
05-09 03:11:04.428: E/AndroidRuntime(1139): at java.lang.Thread.run(Thread.java:841)
05-09 03:11:04.428: E/AndroidRuntime(1139): Caused by: java.lang.ArrayIndexOutOfBoundsException: length=1; index=1
05-09 03:11:04.428: E/AndroidRuntime(1139): at com.hexwhale.pocketcollege.CheckUsername.doInBackground(CheckUsername.java:11)
05-09 03:11:04.428: E/AndroidRuntime(1139): at com.hexwhale.pocketcollege.CheckUsername.doInBackground(CheckUsername.java:1)
05-09 03:11:04.428: E/AndroidRuntime(1139): at android.os.AsyncTask$2.call(AsyncTask.java:288)
05-09 03:11:04.428: E/AndroidRuntime(1139): at java.util.concurrent.FutureTask.run(FutureTask.java:237)
答案 0 :(得分:6)
尝试使用以下内容:
public class CheckUsername extends AsyncTask<String, Integer, String[]>{
@Override
protected String[] doInBackground(String... params) {
// TODO Auto-generated method stub
String username = params[0].toString();
String password = params[1].toString();
System.out.println(username);
System.out.println(password);
return null;
}
}