-
Object errors
hey guys, this is my first post in the forum, probably one of many. My problem is when I'm writing code in eclipse for some reason when i create new custom objects it gives me an error "local variable __ is never read" even if I use it later in the code. I made up a small example of when this happens here: (this example is using Processing, but it also happens to me when I'm doing the same thing in an applet.)
import processing.core.PApplet;
public class BBGame extends PApplet {
Brick[] b = new Brick[1];
public void setup(){
size(800,600);
background(0);
Brick b1_1 = new Brick(0,0); //<-- error under b1_1
b1_1 = b[0];
}
public void draw(){
background(0);
fill(255,255,255);
for(int i = 0; i < b.length; i++){
fill(255,255,255);
rect(10,25,b[i].brickX,b[i].brickY);
}
}
}
-
It's not an error, it's a warning. You've created the b1_1 variable and initialized it with an object reference, but where do you use it in the program?
Oh, and by the way, welcome to the Java-Forums.org!
-
right, it is a warning sorry about that, but my program doesnt reaize its there, like if i try to draw a rectangle at b[i].brickX, b[i].brickY, nothing happens. I use the object when I put it in the array and also in the draw method.
-
Its always useful when posting about errors to include a stack trace - its kinda hard for us to guess what errors you get.
However, your in luck, because my magic cue ball is telling me you get a null pointer exception at this line
Code:
rect(10,25,b[i].brickX,b[i].brickY);
The reason for this is this line:
b1_1 = b[0];
You are assigning b1_1 with the value of whats in b[0] - which is null.
If im right, It should be the other way round -
b[0] = b1_1
-
thanks a ton berkeley, that seems to have worked. however now I am having another problem with the images which I should probably post in another thread