#Need fixing an error
1 messages · Page 1 of 1 (latest)
While you are waiting for getting help, here are some tips to improve your experience:
If nobody is calling back, that usually means that your question was not well asked and hence nobody feels confident enough answering. Try to use your time to elaborate, provide details, context, more code, examples and maybe some screenshots. With enough info, someone knows the answer for sure.
Don't forget to close your thread using the command </help-thread close:1027500463647621170> when your question has been answered, thanks.
I know that problem
If it what in my mind
It happened for me when i gave the array a index bigger than the length of array you declare
could u please share the full error message
not just the name of it
it contains important information on what exactly caused it and where to find the issue
whats line 37 please?
"calculate[i][j] = calculate[i+1][j+1] + grid[i][j];"
okay. so u do a lot of array accesses here
but one of them is out of bounds
the error says that one of those arrays has a length of 2
so it can contain 2 items
but u asked for the third item
which obviously makes no sense
like, imagine having a garage with place for 2 cars. and u try to park a third car in it
so it crashed
oh
now, u should figure out which of those 6 array accesses u make is the bad one
therefore, either use ur debugger
or put a print directly above this line
that is sth like:
System.out.println("i:" + i + ", j:" + j);
System.out.println("calculate.length:" + calculate.length);
System.out.println("calculate[i].length:" + calculate[i].length);
System.out.println("calculate[i + 1].length:" + calculate[i + 1].length);
System.out.println("grid.length:" + grid.length);
System.out.println("grid[i].length:" + grid[i].length);
put this bunch of prints right above line 37
then execute again
then give us what it says right before the crash
like, the last set of those prints
all of them were bad ones since when i kept them, they still crashed with the same error
but when i removed them they provided this result
thanks but i need to see the outputs when the crash happens
and please use println and not print
just put the snippet above line 37 and run it
dont do other modifications
i used println?
left the code and just put the snippet above the code
are u running this in some sort of framework or what is this
a website?
a plugin?
a unit test?
u shouldnt be doing that right now. its contraproductive for debugging
u should take one of their example inputs and execute ur code urself manually
with that input
but anyways, we can see what it says regardless
lets look at this for example
it says that the calculate[i + 1] array has 2 elements in it
that one, sorry
One of the elements are from the loop
and another would've been from + 1
and j is currently 2
so now ur code says
calculate[i+1][j+1]
which is
calculate[1][3]
but calculate[1] only has two elements
and ur asking for index 3
so that crashes
so ur code logic at that point is just incorrect
as simple as that
oh that's a simple way of putting it,
so i'd need to redo it entirely again
thats not what i said
u just have to understand what ur code does and understand that ur thinking at this point is flawed
and introduce a fix for that
but since ur code is really hard to understand, its written very complex and u didnt really give any context, i cant go into more detail since i didnt yet understand ur code
but presumably u do understand it
so by pointing out and explaining the issue, u should now be like "oh yeah! i totally overlooked that aspect. cool, easy to fix"
Closed the thread due to inactivity.
If your question was not resolved yet, feel free to just post a message to reopen it, or create a new thread. But try to improve the quality of your question to make it easier to help you 👍