RSS Forums RSS
Please support our Legacy and Other Languages advertiser: Programming Forums
Views: 1021 | Replies: 1
Join Date: Nov 2007
Posts: 26
Reputation: alcoheca is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
alcoheca alcoheca is offline Offline
Light Poster

J# invalid paramater at runtime

  #1  
Apr 24th, 2008
Hi, I have this issue with a J# project I need to complete for uni.

  1. public class Sprite
  2. {
  3. private Image m_image;
  4.  
  5. public Sprite(Image image)
  6. {
  7. m_image = image;
  8. }
  9.  
  10. public int getWidth()
  11. {
  12. return m_image.get_Width();
  13. }
  14.  
  15. public int getHeight()
  16. {
  17. return m_image.get_Height();
  18. }
  19.  
  20. public void draw(Graphics g, int x, int y)
  21. {
  22. g.DrawImage(this.m_image, x, y);
  23. }
  24. }

This compiles fine, however when I run the program the Image member variable m_image ends up with a Bitmap type rather than an Image.

Here's is the code where the bitmap is loaded, at no point do I cast, or use the bitmap type, so I'm left unsure how to fix it...

  1. public Sprite getSprite(String ref)
  2. {
  3. /* check for cached sprite */
  4.  
  5. if (imageCache.get(ref) != null)
  6. {
  7. return (Sprite)imageCache.get(ref);
  8. }
  9.  
  10. /* not found, load in bitmap now */
  11.  
  12. Image inputFile = null;
  13.  
  14. try
  15. {
  16. inputFile = Image.FromFile(ref + ".bmp");
  17. }
  18. catch (Exception e)
  19. {
  20. System.err.println("Load failed: " + ref + ".bmp");
  21. System.exit(0);
  22.  
  23. }
  24.  
  25. // create a sprite, add it the cache then return it
  26.  
  27. Sprite sprite = new Sprite(inputFile);
  28. imageCache.put(ref, sprite);
  29.  
  30. return sprite;
  31. }
This cause an exception of "invalid paramater".

edit: I'm using the windows classes System.Drawing.* which is why I haven't posted this on the Java forum.
Last edited by alcoheca : Apr 24th, 2008 at 1:15 pm.
AddThis Social Bookmark Button
Reply With Quote  

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 11:40 am.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC