An array index out of bounds exception, I know what that means but.. why!?

wrong quote XD

It’ll probably help to make a mental distinction between array size and array bounds.

·Size: Number of elements contained by the array
·Bounds: Range of valid identifiers for the contained elements.

This distinction will become vital if you need to implement variable size data structures, like lists, stacks or queues, whose array size does not necessarily match the actual bounds.

yeah, organising it did fix the silly AIOOB but it still cant detect when there is a live cell on the same X or Y as the middle, it still only picks up the corners. The logic looks perfect (this is following both mine and yours). If its inside(j, i) AND i does not equal y AND j does not equall X, whats wrong with that!? It skips the line entirely if i = y OR j = x, instead of AND.

if(isInside(j,i) && ((j != x) && (i != y)))

;D You are reminding me of a course I took in college, decades ago, on logic for circuit design. I recall there were interesting ways “not and” could be set up to be the equivalent of “or”; or “not or” used for “and”. We had assignments where we had to use just “nand” or just “nor” gate IC’s (with negations allowed as well).

The best way to find the correct answer might be to just work out the “truth table” by hand.

With a debugger you should be able to make sense of even the most obtuse code.
Stick a break point on the Exception in question, and investigate the state of all the relevant variables at the point the error occurs.

That said, if you can’t understand your own code, what chance do others have?

Always endeavor to write code that’ll be understandable to others, and yourself 6 months down the line!

well, thank you for the help I guess, ;D I fixed the logic problem by simply saying if the cell I’m checking is true, take away one from the number of surrounding cells. And now, I have my very own Game of life!

Try telling that to the people who make examples in the official oracle documentation. If I could understand what they wrote, I’m sure I’d come to forums less often :-\

you’re welcome I guess… :stuck_out_tongue:

Making all the logic gates out of nor gates is fun. :smiley:

if that was true, then people wouldn’t use the help forum, as there would be no point. sometimes people make mistakes and can’t notice them themselves, so they need us (the community :D) to help them. :slight_smile: Besides, we’re all friends here, and more then willing to help. :3

I agree with you, TrinityGamer, but it is also true that some people will not even try to solve the problem themselves before asking for help, so it is always good to remind people that the power is in their own hands.

Also, the community is helpful, but we’re not tech support. :stuck_out_tongue:

Be grateful there are examples. If you start using a library like libGDX you’re going to find a lot less and more inconsistent examples, if they exist at all. Oracle has done a pretty good job with their documentation and tutorials, but in the end it’s up to you to implement whatever you need. If the Oracle examples confuse you, use Google and find another one, not that complicated.

I wasn’t meaning to chastise the OP for asking a question he should have been able to answer himself; I was suggestion the course of action I’d take to resolving his problem*.

*Assuming I had the time & motivation to download his code, paste it into Eclipse, run it to the point it crashes, and analyse how what it’s doing differs from what it’s supposed to be doing.

Glad to hear the OP resolved his issue.

No doubt it IS actually useful in more advanced stages, but for a beginner like me? :-
I could go on youtube tutorials, and that is what I’ve done up until now, but I don’t want to follow a tutorial f you know what I mean.

ONE final problem, I’m sure it can be fixed with one line of code. How do I make it so that the keyboard automatically works without me having to click in the window?

What do you mean by the keyboard automatically working? Detecting key presses? (that’s not possible)

I have a key listener, listening for: enter, shift and control. The window IS the active window upon startup, but before the keyListener can actually pick up anything I have to click the canvas (inside the borders).

call requestfocus() on the canvas

The class with main in it, “Game”, extends canvas and never actually uses it anywhere else. Should it be on the JFrame instead? because that doesn’t work. ???

OK I’m being silly it extends canvas so it can use things like the mouse and bufferstrategies, how would I use the requestFocus() on the Canvas then?

in this case just put


requestFocus();

in your initialization code