• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 763
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 763
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 763
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok. thanks a lot.
 
Jigar Naik
Ranch Hand
Posts: 763
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic