Your basic problem is because your first index you've found here:
locatie = inhoud.indexOf("?");
Then you make a substring and use this same index again here without changing it (except to increment which I guess is intended to exclude the question mark):
parameter = inhoud.substring(++locatie, spatie);
For the input string in your post what you end up with is this:
parameter = inhoud.substring(6, 5);
I think the exception (-2) is indicating the end index (4 since end index is exclusive) is 2 less than the begin index.
I think what you want is either
parameter = inhoud.substring(0, spatie);
or
parameter = inhoud.substring(1, spatie);
Depending on whether or not you want to exclude the question mark.
Also trimming removes trailing and leading whitespace. It's useful if that's something you need to do. In this scenario I'd say it's probably not useful. You've created the first substring based on a non-whitespace character so you can be sure there is not leading whitespace. With the second substring, the end index is exclusive so if you substring on whitespace you can also be sure there is no trailing whitespace.