what variable has a null value?
Which line is line 66? You should not get an error on the call to the System.out.println() method.
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
what variable has a null value?
Which line is line 66? You should not get an error on the call to the System.out.println() method.
If you don't understand my answer, don't ignore it, ask a question.
I don't see anything wrong in this -_-
What is the code on line 66? What you posted doesn't look like it would cause the NPE.
If you don't understand my answer, don't ignore it, ask a question.
Well, based off context... Your Block class extends Rectangle. Engine.sY is a static variable that should looks like it should never have a null value. Also, in your Block class, when you call y and height, you haven't given any values to those variables. When the code executes, y and height remain null until tick is called.
I don't know much about Rectangle, but I'm going to guess that x, y, and height are called like this:
public int x, y, height; // OR public int x; public int y; public int height;
You have to give those variables a value to use other wise their value is null. Take a look here: http://docs.oracle.com/javase/6/docs...Rectangle.html
In tick, what are you trying to print? Also, in this method:
public void render(Graphics g) { if(id != Tile.air) { g.drawImage(Tile.tileset_terrain, (int)x - (int)Engine.sX, (int)y - (int)Engine.sY, (int)x + width - (int)Engine.sX, (int)y + height - (int)Engine.sY, id[0] * Tile.tileSize - (int)Engine.sX, id[1] * Tile.tileSize - (int)Engine.sY, id[0] * Tile.tileSize + Tile.tileSize, id[1] * Tile.tileSize + Tile.tileSize, null); } }
Why are you casting x and y as ints ( the (int)x or (int)y ) when they are ints to begin with? render(Graphics g) is going to throw a NullPointerException just like tick.
--- Update ---
y and height are causing the NPE because in the Rectangle class, they are initialized without a value. Rectangle (Java Platform SE 6)
I don't knooowwwwwww D,:
I am a newb trying to follow a video It all works for him and now this and I don't understand any of it!!!
The guy said that we need to do that because If we don't it won't work and I tried it and it doesn't and his definition of static was changable and then everyone here says it causes problems and I DON'T GET!
I just want my block's height to stay the same! :{
--- Update ---
I'm a scared lil' newb
Find in the code where the image is being drawn. Print out the values used by the drawImage method that controls the height of the image. When you find the value/variable that is making the image get shorter, then backtrack in the code to find out why the values of the variables are changing to make the image shorter.
The code has no comments describing what it is doing or how the different pieces fit together. Can you ask the author for some documentation for the program that explains what it does?I don't understand any of it!!!
If you don't understand my answer, don't ignore it, ask a question.
My advice, follow a different video. Static means that a variable can be accessed (changing is a form of accessing) by simply evoking the class name.
//for example Math.PI; // is a public static final double value in the Math class that is an approximation of Pi.
The fact that I couldn't even get the program to run the way you gave is a HUGE red flag. He even got the main method wrong.
Frankly, if you want to continue with this program, you're going to be frustrated and confused for a long time, at least until you somewhat understand what's going on. Learn the basics of Java then move into GUI's and more advanced algorithms. We will help you if you want to debug this program, the decision is yours.
WolfNinja2 (December 23rd, 2012)
I'm just going to continue with the 2 hour video (As I'm at the last half hour in it) If I find the issue as I go I'll tell you all :/
--- Update ---
The reason that there's (int) in front of all those variables is because they're originally double's (unacceptable for drawing things :p )
If the video is supposed to be teaching how to program java, its using some poor techniques.
Most of the static variables could be final. The others should be instance variables.
The missing documentation in the program is a major fault.
If you don't understand my answer, don't ignore it, ask a question.
WolfNinja2 (December 23rd, 2012)
It's just how to do a game. I learn by following these tutorials over and over and eventually I understand it all and pick up some good concepts. But this is just all going to heck I moved on, we added collision but after the player stops, the camera keeps going. But the variable for the camera's Y isn't being messed with anywhere other than where the player's y is. Do not get.
Stuff like this really down's on my courage to keep up this whole 'Learning Java' :/
Don't be discouraged. It takes a long time to learn. There are different ways to learn than through videos. projecteuler.net is a great programming challenge website. Java works well for most of the problem. I've learned a lot about elegant programming, arrays, and math just by solving a few problems. I'm sure there are other websites like it.