This site requires JavaScript, please enable it in your browser!
Greenfoot back
Damste22
Damste22 wrote ...

2022/1/31

WHY WONT BY WORLD BUILD

Damste22 Damste22

2022/1/31

#
I'm trying to make the virtual piano but it's not the program's not creating my world does anyone know how to fix this. here's my code public class Piano extends World { private String whiteKeys = { "A", "S", "D", "F", "G", "H", "J", "K", "L", ";", "'", "\\" }; private String whiteNotes = { "3c", "3d", "3e", "3f", "3g", "3a", "3b", "4c", "4d", "4e", "4f", "4g" }; private String blackKeys = { "W", "E", "", "T", "Y", "U", "", "O", "P", "", "]" }; private String blackNotes = { "3c#", "3d#", "", "3f#", "3g#", "3a#", "", "4c#", "4d#", "", "4f#" }; /** * Make the piano. This means mostly, apart from defining the size, * making the keys and placing them into the world. */ public Piano() { super(800, 340, 1); makeKeys(); showMessage(); } public void showMessage() { showText("Click 'Run and start to play", 400, 320); } /** * Create the piano keys (white and black) and place them in the world. */ private void makeKeys() { for(int i = 0; i < whiteKeys.length;) { Key key = new Key(whiteKeys, whiteNotes+".wav", "white-key.png", "white-key-down.png"); addObject(key, i*63 + 54, 140); } for(int i = 0; i < blackKeys.length;) { if( ! blackKeys.equals("") ) { Key key = new Key(blackKeys, blackNotes+".wav", "black-key.png", "black-key-down.png"); addObject(key, i*63 + 85, 86); } } } }
danpost danpost

2022/1/31

#
Damste22 wrote...
the program's not creating my world
for(int i = 0; i< whiteKeys.length;)
and
for(int i = 0; i < blackKeys.length;)
The iterators, i, remain at zero (no increments given). So, it is stuck in a loop. World object never completes initializing. In fact, Key objects are created for the first white key multiple times, repeatedly, until memory runs out, whereby you will get a OutOfMemoryException.
You need to login to post a reply.