DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   Legacy and Other Languages (http://www.daniweb.com/forums/forum42.html)
-   -   J# invalid paramater at runtime (http://www.daniweb.com/forums/thread120811.html)

alcoheca Apr 24th, 2008 1:14 pm
J# invalid paramater at runtime
 
Hi, I have this issue with a J# project I need to complete for uni.

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...

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;
        }
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.

alcoheca Apr 30th, 2008 10:50 am
Re: J# invalid paramater at runtime
 
No one has any idea?

start of rant:
MSDN Forums are dead, no one is using J#, my lecturer is useless.. why force us to use this language with such limited support docs, examples, etc...


All times are GMT -4. The time now is 11:06 pm.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC