| | |
J# invalid paramater at runtime
![]() |
•
•
Join Date: Nov 2007
Posts: 26
Reputation:
Solved Threads: 0
Hi, I have this issue with a J# project I need to complete for uni.
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...
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.
java Syntax (Toggle Plain Text)
public class Sprite { private Image m_image; public Sprite(Image image) { m_image = image; } public int getWidth() { return m_image.get_Width(); } public int getHeight() { return m_image.get_Height(); } public void draw(Graphics g, int x, int y) { g.DrawImage(this.m_image, x, y); } }
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...
java Syntax (Toggle Plain Text)
public Sprite getSprite(String ref) { /* check for cached sprite */ if (imageCache.get(ref) != null) { return (Sprite)imageCache.get(ref); } /* not found, load in bitmap now */ Image inputFile = null; try { inputFile = Image.FromFile(ref + ".bmp"); } catch (Exception e) { System.err.println("Load failed: " + ref + ".bmp"); System.exit(0); } // create a sprite, add it the cache then return it Sprite sprite = new Sprite(inputFile); imageCache.put(ref, sprite); return sprite; }
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.
![]() |
Other Threads in the Legacy and Other Languages Forum
- Previous Thread: Countdown timer
- Next Thread: Matlab Help
| Thread Tools | Search this Thread |





