是什么导致hashmap android中的indexoutofbound?

时间:2018-03-21 06:09:19

标签: android hashmap indexoutofboundsexception

 protected String doInBackground(String... strings) {

            hashMap=new HashMap<String, String>();
            hashMap.put("firstname",strings[0]);
            hashMap.put("lastname",strings[1]);
            hashMap.put("email",strings[2]);
            hashMap.put("password",strings[3]);
            finalResult=httpParse.postRequest(hashMap,httpUrl);
            return finalResult;
        }

这是android studio调用Index out of bound错误的代码。

  

引起:java.lang.ArrayIndexOutOfBoundsException:length = 0;索引= 0                                                                                     在   com.example.fayaz.registration.MainActivity $ 1UserRegisterClass.doInBackground(MainActivity.java:98)                                                                                     在   com.example.fayaz.registration.MainActivity $ 1UserRegisterClass.doInBackground(MainActivity.java:76)                                                                                     在android.os.AsyncTask $ 2.call(AsyncTask.java:295)                                                                                     在java.util.concurrent.FutureTask.run(FutureTask.java:237)                                                                                     在android.os.AsyncTask $ SerialExecutor $ 1.run(AsyncTask.java:234)                                                                                     在   java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)                                                                                     在   java.util.concurrent.ThreadPoolExecutor中的$ Worker.run(ThreadPoolExecutor.java:588)                                                                                     在java.lang.Thread.run(Thread.java:818)

1 个答案:

答案 0 :(得分:0)

您正在使用varargs doInBackground(String... strings)

strings数组的长度为0,因此是ArrayIndexOutOfBoundsException。