How must I initialize a Graphics object?


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 10 of 10

Thread: How must I initialize a Graphics object?

  1. #1
    Join Date
    Jun 2003
    Posts
    17

    How must I initialize a Graphics object?

    Hi,
    I've a problem with Graphics Abstract class;
    how must I do to initialize a Graphics object?

    I must execute this code:

    Graphics gr;
    gr.drawString("Image",30,0);
    gr.drawString("not",30,30);
    gr.drawString("Found",30,60);
    image.paintIcon(null,gr,0,0);

    the compiler returns my the error:
    "gr not initialized"

    How can I do to initialize this last?

    Thank.



    anonimocampano@katamail.com
    (capienza 2,5 Mb)

  2. #2
    Join Date
    Mar 2003
    Posts
    86

    DebugGraphics

    You can not instanciate a Graphics object. What you can do is use DebugGraphics.

    Sharbov.

  3. #3
    Join Date
    Jun 2003
    Posts
    17
    Using DebugGraphics, when I compile, I've a null pointer exception.

    Why?
    How Must I rewrite the code?

    Thank.



    anonimocampano@katamail.com
    (capienza 2,5 Mb)

  4. #4
    Join Date
    Mar 2003
    Posts
    834
    I'm guessing your code looks like:
    Code:
    DebugGraphics dgr;
    dgr.drawString("Image",30,0);
    dgr.drawString("not",30,30);
    dgr.drawString("Found",30,60);
    image.paintIcon(null,gr,0,0);
    Of course you're going to get a NullPointerException. You have declared a DebugGraphics REFERENCE variable called 'dgr'. At no point have you created a DebugGraphics OBJECT and assigned it to the reference.

    What you want:
    Code:
    DebugGraphics dgr = new DebugGraphics();
    dgr.drawString("Image",30,0);
    dgr.drawString("not",30,30);
    dgr.drawString("Found",30,60);
    image.paintIcon(null,gr,0,0);
    ArchAngel.
    O:-)

  5. #5
    Join Date
    Jun 2003
    Posts
    17
    I have the null pointer exception just when the DebugGraphics object is create.

    I don't know why.All seems OK.

    I'll wait...

    Thanks.



    anonimocampano@katamail.com
    (capienza 2,5 Mb)

  6. #6
    Join Date
    Mar 2003
    Posts
    834
    "I have the null pointer exception just when the DebugGraphics object is create."

    Is that when you run my code?

    "I don't know why.All seems OK."

    These seem to be two conflicting statements! Did it work or not?
    ArchAngel.
    O:-)

  7. #7
    Join Date
    Jun 2003
    Posts
    17
    Yes,
    when I run your code;

    I've a null pointer exception at the line in which DebugGraphics object is create:

    DebugGraphics gr = new DebugGraphics();



    anonimocampano@katamail.com
    (capienza 2,5 Mb)

  8. #8
    Join Date
    Mar 2003
    Posts
    834
    I don't belive you! ;-)

    Please post the stack trace.

    ArchAngel.
    O:-)

  9. #9
    Join Date
    Jun 2003
    Posts
    17
    I don't know how copy the stackTrace text;
    so I have attached the image of it.

    I think is the same.

    Then, can you explain me how to copy the stackTrace directly for the code of the program, and out of the program in the dos shell.

    Thank.
    Attached Files Attached Files



    anonimocampano@katamail.com
    (capienza 2,5 Mb)

  10. #10
    Join Date
    Mar 2003
    Posts
    834
    Stack trace: Highlight the text in the console using the mouse. Then right-click. The text is now in clipboard. Now past it into wherever you'd like.

    The Problem: I came into this problem a little late, what are you actually trying to do? I've always obtained graphics contexts from controls, rather than creating new ones.
    ArchAngel.
    O:-)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center