Results 1 to 5 of 5
Thread: Object errors
- 10-30-2010, 09:39 PM #1
Member
- Join Date
- Oct 2010
- Posts
- 41
- Rep Power
- 0
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!
- 11-02-2010, 09:19 PM #3
Member
- Join Date
- Oct 2010
- Posts
- 41
- Rep Power
- 0
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.
- 11-02-2010, 10:57 PM #4
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
The reason for this is this line:Java Code:rect(10,25,b[i].brickX,b[i].brickY);
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
- 11-03-2010, 01:22 AM #5
Member
- Join Date
- Oct 2010
- Posts
- 41
- Rep Power
- 0
Similar Threads
-
Create object of unknown class, based on existing object
By Zack in forum New To JavaReplies: 2Last Post: 06-22-2010, 04:29 AM -
[Paremeters] in a method(Object expA, Object expB){}
By Unsub in forum New To JavaReplies: 2Last Post: 01-29-2010, 02:01 AM -
What is the difference between Semantic Errors and Logical Errors?
By tlau3128 in forum New To JavaReplies: 3Last Post: 03-08-2009, 01:51 AM -
how to pass an arraylist from an object back to the parent object that it was created
By george_a in forum New To JavaReplies: 1Last Post: 03-04-2009, 06:14 PM -
Parsing a superclass object to subclass object dynamicly
By Andrefs in forum Advanced JavaReplies: 1Last Post: 07-22-2008, 04:27 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks