Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Jigar Naik
Ranch Hand
Posts: 762
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

 
Joe Ess
Bartender
Posts: 9319
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So you have code that does this:


and invokes a method that does this:

and gets a null pointer exception? Yea, that sounds correct.
 
Jigar Naik
Ranch Hand
Posts: 762
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ya but i'm not really getting what should i assign to Graphics g = ??? in my servlet ???
 
Joe Ess
Bartender
Posts: 9319
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 762
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok. thanks a lot.
 
Jigar Naik
Ranch Hand
Posts: 762
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9319
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic