❔ ✅ IndexOutOfRangeException
I just tried to code out a simple app that reads a .csv file (as per screenshot) and displays the content in the columns "state" and "city" . My Main points out an IndexOutOfRangeException, so something is out of the range. But I am lost to find it out now.
Could anyone point me in the right direction?
My other classes for this project is here - FYI:
https://github.com/morry239/HashTableRedBook/blob/master/ZIPCodeSearch/ZIPCodeSearch.cs
GitHub
HashTableRedBook/ZIPCodeSearch.cs at master · morry239/HashTableRed...
Contribute to morry239/HashTableRedBook development by creating an account on GitHub.
13 Replies
If you don't pass any command line arguments, args will be empty
You can define arguments when debugging in the project properties
A couple of more beginner questions - you mean something like this? https://www.jetbrains.com/help/rider/Unreal_Engine__EzArgs.html#arguments_ezargs
JetBrains Rider Help
Add Program Arguments and Environment Variables | JetBrains Rider
If not, shall I enter the valid string into somewhere in the code? The debugging showed that I have some null strings as per screenshot
@TheBoxyBear
This
Though this only when debugging. Once released, the user still has to provide the arguments to the executable so you still need to check if the array is empty
The debug option is Rider adding the arguments automatically when running the program.
Ok I think my problem is now find out what kind of the argument I shall enter into (something along the lines of "if array is null == do this" right?)
I have installed the EzArgs plugin mentioned by the JetBrains article and did this:
It still triggers the Index out of range", so I think my query here is wrong
The arguments are the values you want in the args array
The length check needs to be in your code
Checking the length, not if it's null
So this is my progress so far
`
I still don't know how to add the length check in here (maybe something like "long length = streamReader.BaseStream.Length;"). But this code gave me some another error I have never seen yet:
`
So I think the problem shifted from the index out of range to something else (most likely the invalid file path referenced somewhere in the code). What do you think?
@TheBoxyBear
Without a drive letter in the path, the path is relative to the location of the executable
For the length check, it's as simple as checking
args.Length > 0
I am on MacBook, so my computer does not have a drive letter in the path(C:, F: you mean any of these right?).
I have made a few more changes to my code:
The index out of range error is gone now, so your advice to add length check worked (I think). This app still has problems, but I will set up another thread separately. Thank you so much for the guidance 🙂
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.