string index outofbounds exception

CD Tom

Member
Licensed User
Longtime User
I don't know why I'm getting this error because it was working before and I only added some columns to the csv file. Here's what I did.
In my access database I've created a query that extracts data to a .csv file the original query worked just fine I would email the file to my android device and save it in the download directory. My program would copy that file to the DirDefaultExternal with this code.
B4X:
      If File.Exists(File.DirRootExternal,"download/MBRS.csv") = True Then
         File.Copy(File.DirRootExternal,"download/MBRS.csv",File.DirDefaultExternal, "MBRS.csv")

      End If
The program would then run this code
B4X:
      table = su.LoadCSV(File.DirDefaultExternal, "MBRS.csv", ",")
This was working fine until I add some columns to the query that extracts to the .csv file now when the above line is executed I get the error "table = su.LoadCSV(File.DirDefaultExternal, "MBRS.csv", ",") java.lang.StringIndexOUtOfBoundsException: Length=48 index=1"
I tried to attach the .csv file but I get an invalid file when I try and upload it.
What do you need to help me find out what I did to get his error.
 
Last edited:

CD Tom

Member
Licensed User
Longtime User
I'm so at a loss I have no idea what to look for. I've even gone back to the original MBRS.csv file and get the same error. Can anyone tell me what causes the error StringIndexOutofBoundsException Length: 48 Index -1 if I had some idea what I could have done then maybe I can fix this.
I've add the complete program in case you need it.
 

Attachments

  • mbrsapp.zip
    26.3 KB · Views: 156
Last edited:
Upvote 0

klaus

Expert
Licensed User
Longtime User
Tow points, I don't know if it will solve your problem.
1) Are you sure that in Table1.SetHeader you have all columns ?
2) In the csv file all data are within double quotes in one of your older files all data are without double quotes.

Best regards.
 
Upvote 0

CD Tom

Member
Licensed User
Longtime User
When you say table1.setheader I don't have anything like that in my code. What is that and how do I put it in my code?
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
You need to make sure that the file MBRS.csv is located in the download folder of the device. I copied it to that folder and your program worked fine after that. I as able to search members. That is the only thing wrong I noticed.
 
Upvote 0

CD Tom

Member
Licensed User
Longtime User
I did the same thing, I copied the MBRS.csv to the download folder then changed the table = su.loadCSV(File.DirRootExternal, "download/MBRS.csv", ",") and ran it but I get the same error.
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
You should not have changed that line. Keep like it was in the zip file you posted. It should be like this:
B4X:
table = su.LoadCSV(File.DirDefaultExternal, "MBRS.csv", ",")
It should be like this for it to work because you are copying the csv file from DirRootExternal to DirDefaultExternal in your code
 
Upvote 0

CD Tom

Member
Licensed User
Longtime User
I still get the error stringindexoutofboundsexternal I'm about ready to quit I just don't understand why you are getting it to work and mine will not work.
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
Tom:
Here is what I did, nothing magic:
1. I unzipped and installed your app. I did not make any modifications to your programs.
2. I copied the csv file you posted a day or so ago to the download folder of the DirRootExternal. In my case DirRootExternal is not in the SD card proper. It is part of the internal memory, but referred to as DirRootExternal.
3. I ran the app. It went through the indexing and so forth, then I clicked on search button on your form. I started typing names and it workedThat is all. Let us hope that Professor Klaus can pull is magic.
 
Upvote 0

CD Tom

Member
Licensed User
Longtime User
Well, I'm back at it again today. I did the same thing as you took the zip I had attached created a new program and tried it guess what I get the same error. I'm wondering if I should reinstall the B4android program. This just doesn't make any sense.
Anybody got other suggestions.
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
Sure you don't have a 'corrupted' or badly edited csv file at your device?
I would suggest copying a fresh copy of your file either from assets or manually.
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
Reinstalling the program doesn't necessarily mean that the file is reinstalled.
 
Upvote 0

CD Tom

Member
Licensed User
Longtime User
Ok, what I did was start a new project, downloaded the zip file of my program and unzipped it into a new directory on my computer. I then selected open source under file and selected the new directory and select the program. I just don't know why I get that stringindexoutofboundsexception length = 48 index = -1 what does the index -1 mean? It almost sounds like there is nothing in the file. I have uninstalled the program from my nexus and have run the compiler and installed the program again on the nexus.
 
Last edited:
Upvote 0

CD Tom

Member
Licensed User
Longtime User
Ok, this time I started a complete new project and reentered everything, and as soon as I hit this line of code
B4X:
Dim su as StringUtils
Dim table as list

table = su.LoadCSV(File.DirDefaultExternal, "MBRS.csv", ",")
I get the stringindexoutofboundsexception length 48 index -1
I don't know where to go or what to do. What else can I try???

In looking at the libs I see my version of StringUtils is 1.02 don't know if that makes any difference
 
Last edited:
Upvote 0

CD Tom

Member
Licensed User
Longtime User
Mahares,
If you still have my program working can you zip it up and let me try it. I don't know if it will make any difference but don't know what else to do.
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
I think you best bet is to again zip you full project and export as zip and include the csv file as you have it, so forum users have a chance to test it on their devices. You probably also need to indicate exactly where you are storing the CSV file initially. Although I did not get an error when I ran it a few days ago even with the new fields, here are a few things to consider down the road when dealing with text files:
1. Avoid comma separated files when you have already commas in the field data. I saw that you have commas in some of the last names. The best way to use a text file when there are comma in the data is to use a TAB delimited text file or semi colon separated file.
2. Most data in that new text file have double quotes as a qualifier. You did not have that in your original text file that had fewer fields. I do not know if that can cause problems.


ADDED: Here is zipped you program. It is exactly the way you posted it. I did not change any code except the package name. It ran for me. Here is what I did:
1. I Installed it on a Nexus 7
2. I copied the csv file you posted (the new one with the added fields) from my PC to the Download folder of the Nexus.
3. Ran the program. No error. Then I clicked on the Search Button. I was able to search. That is the extent of the testing I did. I did not do any other testing. I only tested to see if I get the same error you did. If you need your csv file, I can zipped for you also, but I assume you still have it.
 

Attachments

  • CDtomMemebers011313.zip
    26.3 KB · Views: 133
Last edited:
Upvote 0
Top