Results 1 to 4 of 4
  1. #1
    hannes is offline Member
    Join Date
    Nov 2009
    Posts
    54
    Rep Power
    0

    Default painting problem

    Hey guys,

    I'm making a program to draw graphs. I have an object 'Line' who containt an array with numbers where a real line must be drawn of( bad english ) and a color. These lines are all in one arraylist. There is one other object who considers these lines. Now, I've made a canvas where the graph must be drawn on. There is another method 'drawgraph' who has the arraylist of lines as parameter. I've also a data who represents the arraylist of lines. the drawgraph methode sets it's data member equals to the parameter. Then it calls the repaint( ). When the paint method is invoked, the graph must be drawn. The lines to be drawn are in the arrayList. This works, but now: if i initialize the canvas the repaint method is invoked and the paint also, thus the graph is drawn, but there are no lines te draw. The arraylist with the lines in it is not initilized either so a nullpointer exception occurs. Can anyone help me with that?

    Thanks, Hannes

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

    Default

    NullPointerExceptions are usually pretty straightforward to resolve. See which object is null and then walk back in your code and see why it wasn't properly initialized. Otherwise I don't see how we'll be able to guess what is not working based on just descriptions and not code.

  3. #3
    hannes is offline Member
    Join Date
    Nov 2009
    Posts
    54
    Rep Power
    0

    Default

    Well, it is a lot of code, over 1000 lines. The nullpointerexception occurs because my arraylist in the canvas isn't initialized. But if i do, I've an arraylist in my canvas and one in my lineholder. These two become thesame only if the user wants to draw. Thus in the beginnin i have two arraylists and later they become 1. But i'm looking for a better solution that you don't need 2 in the beginning. If anyone can help me with that

  4. #4
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,560
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by hannes View Post
    Well, it is a lot of code, over 1000 lines. The nullpointerexception occurs because my arraylist in the canvas isn't initialized. But if i do, I've an arraylist in my canvas and one in my lineholder. These two become thesame only if the user wants to draw. Thus in the beginnin i have two arraylists and later they become 1. But i'm looking for a better solution that you don't need 2 in the beginning. If anyone can help me with that
    You either have lines to draw or you haven't; if you can decide that you haven't if an arraylist happpens to be null, fine, don't draw anything then in your paintComponent(Graphics g) method.

    kind regards,

    Jos

Similar Threads

  1. JPanel not always painting everything
    By ekted in forum AWT / Swing
    Replies: 0
    Last Post: 11-26-2009, 11:24 AM
  2. Replies: 12
    Last Post: 10-09-2009, 06:26 AM
  3. Jpanel painting problem
    By kcakir in forum AWT / Swing
    Replies: 3
    Last Post: 04-15-2009, 10:21 PM
  4. Applets painting outside borders in web browsers
    By sirdori in forum New To Java
    Replies: 2
    Last Post: 11-20-2008, 06:14 PM
  5. Hovering mouse over a button and painting
    By gtraylo in forum AWT / Swing
    Replies: 2
    Last Post: 04-24-2008, 09:33 AM

Posting Permissions

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