我正在尝试从响应对象中的数据库获取数据并将其显示在客户端。但是我让这个数组索引超出了界限异常。我确信我做对了,但不能让它运行。我得到的错误是
java.lang.ArrayIndexOutOfBoundsException: length=1956; index=1956
at com.pda.kaizen.ConnectionImpl.getCustomers(ConnectionImpl.java:139)
at com.pda.kaizen.activity.MainMenuActivity$1.run(MainMenuActivity.java:123)
at java.lang.Thread.run(Thread.java:856)
这是服务器端代码
StringBuilder sb = new StringBuilder();
sb.append("100|OK");
for (Customer customer : customers) {
sb.append("|").append(customer.getId())
.append("|").append(customer.getCode())
.append("|").append(customer.getName())
.append("|").append(customer.getNameFarsi())
.append("|").append(customer.getAddress())
.append("|").append(customer.getType())
.append("|").append(customer.getPhoneNo())
.append("|").append(customer.getMobileNo())
.append("|").append(customer.getFaxNo())
.append("|").append(customer.getEmail())
.append("|").append(customer.getRegisterCode())
.append("|").append(customer.getOrganizationName())
.append("|").append(customer.getEconomicCode())
.append("|").append(customer.getMelliCode())
.append("|").append("-1".equals(customer.getPostCode())?"":customer.getPostCode())
.append("|").append(customer.getFirstName())
.append("|").append(customer.getLastName());
}
return sb.toString();
这是活动代码
@Override
public List<Customer> getCustomers() {
List<NameValuePair> params = new ArrayList<NameValuePair>(1);
params.add(new BasicNameValuePair("action", "customer"));
try {
String response = executeHttpPost(params);
String[] result = response.split(DELIMITER);
List<Customer> customers = new ArrayList<Customer>();
for (int i = 2; i < result.length - 16; i += 17) {
String id = result[i + 0];
String code = result[i + 1];
//String name = result[i + 2];
String name = result[i + 3];
String address = result[i + 4];
String type = result[i + 5];
String phone = result[i + 6];
String mobile = result[i + 7];
String fax = result[i+8];
String email = result[i+9];
String registerCode = result[i+10];
String organizationName = result[i+11];
String economicCode = result[i+12];
String melliCode = result[i+13];
String postCode = result[i+14];
String firstName = result[i+15];
String lastName = result[i+16];
Customer customer = new Customer(id, code, name, address, type,phone,mobile,fax,email,registerCode,organizationName,economicCode,melliCode,postCode,firstName,lastName);
customers.add(customer);
}
return customers;
}
catch (Exception exc) {
Log.e("----", exc.getMessage(), exc);
throw new ConnectionException(exc.getMessage());
}
}