I can't find my error ;/

Hello,i just recently started programming in java.I watched all of TheNewBoston’s beginners tutorials and then hopped right away in to game development.I found some nice tutorials on how to make a small Minecraft 2D Creative version,i got to the part where the guy coded the block placing event i did everything exactly like he did (or at least i think that i did it the exact same way) but it does not work for me ;/.


public class Level {
	public int worldW = 50,worldH=50;
	public Block[][] block = new Block[worldW][worldH];
	
	public Level(){
		for(int x=0;x<block.length;x++){
			for(int y=0;y<block[0].length;y++){
				block[x][y] = new Block(new Rectangle(x * Tile.tileSize, y * Tile.tileSize, Tile.tileSize, Tile.tileSize), Tile.air);
			}
		}
		
		generateLevel();
	}
	

	
	public void generateLevel(){
		//generating mountains,earth etc.
		for(int y=0;y<block.length;y++){
			for(int x=0;x<block[0].length;x++){
				if (y>worldH/4){
					
					if(new Random().nextInt(100)>20){
					
					try{
						if(block[x-1][y-1].id== Tile.earth){
							
							block[x][y].id = Tile.earth;
						}
					}catch(Exception e){}
					}
					if(new Random().nextInt(100)>30){
					try{
						if(block[x+1][y-1].id== Tile.earth){
							block[x][y].id = Tile.earth;
						}
					}catch(Exception e){}
					}

					try{
						if(block[x][y-1].id== Tile.earth){
							block[x][y].id = Tile.earth;
						}
					}catch(Exception e){}
					
					
					if(new Random().nextInt(100)<5){
						block[x][y].id = Tile.earth;

					}
				}
			}
		}
		//placing grass
		for(int y=0;y<block.length;y++){
			for(int x=0;x<block[0].length;x++){
				if(block[x][y].id == Tile.earth && block[x][y-1].id == Tile.air){
					block[x][y].id = Tile.grass;
				}
				
			}
		}

		}
		
	
	public void building(int camX,int camY,int renW,int renH){
		if(Component.isMouseLeft || Component.isMouseRight){
		for(int x=(camX/Tile.tileSize);x<(camX/Tile.tileSize) +renW;x++){
			for(int y=(camY/Tile.tileSize);y<(camY/Tile.tileSize)+renH ;y++){
				if(x >= 0 && y >= 0 && x < worldW && y< worldH){
					if(block[x][y].contains(new Point((Component.mse.x  /Component.pixelSize)+(int)Component.sX,(Component.mse.y /Component.pixelSize)+ (int)Component.sY))){
						int sid[] = Component.inventory.invBar[Inventory.selected].id;
						
						if(Component.isMouseLeft){
							block[x][y].id = Tile.air;
						
						}else if (Component.isMouseRight){
							if(sid == Tile.earth||sid == Tile.grass||sid == Tile.sand){
								block[x][y].id = sid;
								
							}
						}

						
						break;
						
					}
				}
			}
		}
		
	}
	}
	
	public void tick(int camX,int camY,int renW,int renH){
	
		building(camX,camY,renW,renH);
	}
	
	public void render(Graphics g,int camX,int camY,int renW,int renH){
		for(int x=(camX/Tile.tileSize);x<(camX/Tile.tileSize) +renW;x++){
			for(int y=(camY/Tile.tileSize);y<(camY/Tile.tileSize)+renH ;y++){
				if(x >= 0 && y >= 0 && x < worldW && y< worldH){
					
				
				block[x][y].render(g);
				}
			}
		}
		
	}
	
}

He codes the block placing at around 1h : 38min

http://www.youtube.com/watch?v=JHxtxfUU5Is Does anyone have an idea why mine doesnt work ?

Off-Topic :

trust me, you don’t wanna do that, you will keep facing tons of problems in the future and you will not be able to write any program or game without a tutorial for that, i’ve spend more than 2 months learning the java basics and then i did the same mistake you are doing now, i jumped right into game development and now am regretting that a lot! and am planning to recap what i skipped, and one more thing, try to not learn from video tutorials, books,articles or code examples are the best resources to learn programming (or any other science)

On-Topic :
are you able to compile and run your game or do you get an error ?? if so, what is the error ?
if you don’t get any error, try to print your exceptions, adding an empty catch block is kinda of a bad habit

Yeah you are probably right ;/ i cant do much without a tutorial but i at least want to finish this game.I do not get any errors ;/ whenever i right click im supposed to place a block/tile but it doesnt place itself.The game and everything else in it (movement,animation and jumping) runs perfectly fine.

are you sure that your mouse inputs works ??
try to print a message when you do a right click and see if you get it or not

Thanks a lot for reminding me to check the Listeners i found the error :stuck_out_tongue: also do you have any book recommendations for beginners ?

glad you found it ;D clicking the appreciate button is very welcome too ::slight_smile:

[quote]do you have any book recommendations for beginners ?
[/quote]
the book i start with is Java Programming for Kids, Parents and Grandparents i found it very simple and easy to follow, after that (i didn’t finish it :-\ ) i jumped to the ZetCode 2D games tutorials but then i realized (thanx to JGO community) that Java2D is not what a Java Game Developer should work with.
My advice to you is to learn Java until you feel that you can write any program by your own (well not any, but you get the idea) during that process you must be very familiar with Java2D which you will not be using it in game development, why ?? short answer : you have BETTER options,
it you still want to know more, read this topic :
why are people trying to use Java2D to make games?

good luck

If you just started with java, you shouldn’t start with games…

http://fivedots.coe.psu.ac.th/~ad/jg/

Best book ever.
Little outdated but it will give you the context of java + game.

You have try…catch blocks which are doing nothing. Seriously, this is the most evil thing you can do in your code. You potentially have NullPointerExceptions, ArrayIndexOutOfBoundsExceptions happening to name just a couple, but you want to completely ignore them? This will end in pain. Don’t do it.