Вопрос

I am trying to use AsyncTask (Learning) ,,Getting Fatal Exception error This is the call

        String username = usr_number.getText().toString();
        String password = password_main.getText().toString();
        String[] Loginvalues = {username,password};

        new CheckUsername().execute(Loginvalues);

And this is the Class

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;
    }

}

This is the Error i am getting

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)
Это было полезно?

Решение

Try using the following:

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;
}

}
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top