Results 1 to 5 of 5

Thread: Object errors

  1. #1
    dyelax is offline Member
    Join Date
    Oct 2010
    Posts
    41
    Rep Power
    0

    Default 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);
    }
    }
    }

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    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!

  3. #3
    dyelax is offline Member
    Join Date
    Oct 2010
    Posts
    41
    Rep Power
    0

    Default

    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.

  4. #4
    berkeleybross's Avatar
    berkeleybross is offline Senior Member
    Join Date
    Feb 2010
    Location
    England
    Posts
    187
    Rep Power
    5

    Default

    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
    Java 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

  5. #5
    dyelax is offline Member
    Join Date
    Oct 2010
    Posts
    41
    Rep Power
    0

    Default

    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

Similar Threads

  1. Replies: 2
    Last Post: 06-22-2010, 04:29 AM
  2. Replies: 2
    Last Post: 01-29-2010, 02:01 AM
  3. Replies: 3
    Last Post: 03-08-2009, 01:51 AM
  4. Replies: 1
    Last Post: 03-04-2009, 06:14 PM
  5. Replies: 1
    Last Post: 07-22-2008, 04:27 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •