aspose file tools*
The moose likes Other JSE/JEE APIs and the fly likes Null pointer exception in g.drawImage(.....) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "Null pointer exception in g.drawImage(.....)" Watch "Null pointer exception in g.drawImage(.....)" New topic
Author

Null pointer exception in g.drawImage(.....)

Jigar Naik
Ranch Hand

Joined: Dec 12, 2006
Posts: 755
Hi,

i am developing one web based blogging application in which when user upload jpg image i am trying to resize the image,

following is the code in my servlet from which i am calling the paint(g) method which is defind in my java class named BlogUtils. and i'm getting exception in drowImage method, null pointer
Servlet Code.. which call paint method of java class model


Java Class's Paint method which is being called from Servlet



On the console



Jigar Naik


Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8867
    
    8

So you have code that does this:


and invokes a method that does this:

and gets a null pointer exception? Yea, that sounds correct.


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Jigar Naik
Ranch Hand

Joined: Dec 12, 2006
Posts: 755
ya but i'm not really getting what should i assign to Graphics g = ??? in my servlet ???
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8867
    
    8

Graphics represents the drawing context for a paricular component or image, so you must create that component and ask it for its Graphics instance before using it. However, if you are just trying to resize an image, you're doing more steps than necessary. BufferedImage extends Image and Image contains a method that you may find helpful. . .
Jigar Naik
Ranch Hand

Joined: Dec 12, 2006
Posts: 755
ok. thanks a lot.
Jigar Naik
Ranch Hand

Joined: Dec 12, 2006
Posts: 755
Hi,

I have gone through the link given for BufferedImage and Image but didn't find any method helpful for resizing image.

There is a constructor for BufferedImage but that even did not help me

Constroctor in my code.
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8867
    
    8

The reason why your code doesn't work is because you create a 100x100 image, then replace it with an image you read in from a file.
There are 7 methods in java.awt.Image. Only one of them returns an image. Give the documentation another look. . .
[ April 10, 2007: Message edited by: Joe Ess ]
 
Consider Paul's rocket mass heater.
 
subject: Null pointer exception in g.drawImage(.....)