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 6374979
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:33:20+00:00 2026-05-25T01:33:20+00:00

I am having an issue while parsing a CSV file. It is only 2

  • 0

I am having an issue while parsing a CSV file. It is only 2 rows of data with a comma separating them. Row one is a date and row 2 is a value. The date field will always have dates in it but sometimes the value is blank (or null?). When it gets to the null value I get a StringIndexOutOfBoundsException and the app crashes. I am logging each loop and can see the data but as soon as I get to a null value it stops looping and gives the error. If there are no null values then it works perfect. Here is my code:

        BufferedReader buf = new BufferedReader(new StringReader(file));
        String line = null;
        while ((line = buf.readLine()) != null) {
            try {
                String date = null, value = null;
                String[] RowData = line.split(",");
                date = RowData[0];
                value = RowData[1]; (this is the row it crashes on)

This is what the CSV looks like:

2011-08-28 09:16,8.23

2011-08-28 09:15,8.24

2011-08-28 09:14,8.26

2011-08-28 09:13,8.34

2011-08-28 09:12,

2011-08-28 09:11,10.72

2011-08-28 09:10,

2011-08-28 09:09,

the value at 09:13 is the last thing in logcat before I get the error.

This fixed it:

                if(RowData.length == 2) {
                    date = RowData[0];
                    value = RowData[1];
                } else {
                    date = RowData[0];
                    value = "0";
                }

I wrote a 0 in the value field so later processes will not choke on the null value. Thanks for all your help guys!

  • 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-05-25T01:33:21+00:00Added an answer on May 25, 2026 at 1:33 am

    You want to do this or something like it:

    String date = null, value = null;
    String[] RowData = line.split(",");
    date = RowData[0];
    
    if(RowData.length ==2)value = RowData[1]; (this is the row it crashes on)
    

    Or some variation of it e.g. if(RowData.length < 2) dont attempt to read the value. Its a pretty standard thing – if you ask an array for an index of a value it doesn’t have Java will crash.

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

Sidebar

Related Questions

I'm having an issue while deleting row key in Cassandra. Whenever I delete Row
I'm having some issues with parsing CSV data with quotes. My main problem is
I've having issues with parsing JSON data from a php file through to JQuery.I've
I am having issue while showing a WebView in an activity in the middle
I am having a crash issue while playing video in iphone 4.0 OS. Actually,
I'm running into a crash issue while developing an iPhone app with Core Data.
Having and issue with an ejabberd cluster. While trying ping the first node from
I am having an issue is that while exporting a report to excel sheet,
I am having an issue testing alternate views while sending HTML E-Mails. I am
I am having an issue removing elements of a list while iterating through the

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.