Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8612111
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T04:32:47+00:00 2026-06-12T04:32:47+00:00

I am trying to get data from the db in the response object and

  • 0

I am trying to get data from the db in the response object and showing it on the client side. But I am getting this array index out of bounds exception.I am sure I am doing it correct,but just cant make it run.
the error I get is

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)

this is the server side code

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();

This is the Activity code

@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());
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T04:32:48+00:00Added an answer on June 12, 2026 at 4:32 am

    I may be wrong – but I believe your problem is with how you split your string.

    If you do this: "a|b|c".split("\\|") – you will get an array of 3 strings.
    If you do this: "a||".split("\\|") – you will get an array of 1 string.

    This is because split trims out the end.

    Assuming you are using split – check your data and see if the last customer has a last name.
    If no – then I am correct.

    See the following ideone code as a sample:
    Example of code failing due to empty data

    To solve the problem, you should introduce spaces between delimiters (or any other value you wish) to ensure split takes them into account.

    See the following ideone code as an example:
    Example of code running with spaces between delimiters.

    NOTE: Quote from the javadoc

    Splits this string around matches of the given regular expression.
    This method works as if by invoking the two-argument split method with
    the given expression and a limit argument of zero. Trailing empty
    strings are therefore not included
    in the resulting array.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to get my data from a query string, but use it
I am trying to get some data from a GoogleCheckout response. I am using
So I'm trying to get data from my sql database and sort it by
I am trying to get data from my interface, written in c, to another
I'm trying to get some data from a certain web-based api using the libcurl
I'm trying to get character data from www.wowarmory.com using PHP and cURL. The code
I am trying to get data back from a PHP file assigned with GET
I'm trying to get some data from a table, where the tag has no
Using php I am trying to get some data from a .csv file which
for example I'm trying to get the data from database like: using (ExplorerDataContext context

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.