irvinedotnet
irvinedotnet

Reputation: 175

unable to use imageview

I have a very simple monotouch applicaiton where I am trying to reference image in an uiimageview but I am not successful. Following is the listing of code and the error I keep getting. Please help. I don't know what am I doing wrong.I have double checked that GoldenGate.jpg is part of my project

using System;
using System.Collections.Generic;
using System.Linq;
using MonoTouch.Foundation;
using MonoTouch.UIKit;

namespace helloworld10
{
    public class Application
    {
        static void Main (string[] args)
        {
            UIApplication.Main (args);
        }
    }

    // The name AppDelegate is referenced in the MainWindow.xib file.
    public partial class AppDelegate : UIApplicationDelegate
    {
        // This method is invoked when the application has loaded its UI and its ready to run
        public override bool FinishedLaunching (UIApplication app, NSDictionary options)
        {
            // If you have defined a view, add it here:
            // window.AddSubview (navigationController.View);

            UIImage image = UIImage.FromFile("GoldenGate.jpg");
            UIImageView imageview = new UIImageView(image);

            Console.WriteLine ("hello world");

            window.MakeKeyAndVisible ();



            return true;
        }

        // This method is required in iPhoneOS 3.0
        public override void OnActivated (UIApplication application)
        {
        }
    }
}

However, I get the following error. Please help me

Error connecting stdout and stderr (127.0.0.1:10001)

Unhandled Exception: System.ArgumentNullException: Argument cannot be null.
Parameter name: image
  at MonoTouch.UIKit.UIImageView..ctor (MonoTouch.UIKit.UIImage image) [0x00064] in /Users/plasma/Source/iphone-3/monotouch/UIKit/UIImageView.g.cs:106 
  at helloworld10.AppDelegate.FinishedLaunching (MonoTouch.UIKit.UIApplication app, MonoTouch.Foundation.NSDictionary options) [0x0000b] in /Users/zulfiqarsyed/Projects/helloworld10/helloworld10/Main.cs:28 
  at (wrapper managed-to-native) MonoTouch.UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr)
  at MonoTouch.UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x00038] in /Users/plasma/Source/iphone-3/monotouch/UIKit/UIApplication.cs:26 
  at MonoTouch.UIKit.UIApplication.Main (System.String[] args) [0x00000] in /Users/plasma/Source/iphone-3/monotouch/UIKit/UIApplication.cs:31 
  at helloworld10.Application.Main (System.String[] args) [0x00000] in /Users/zulfiqarsyed/Projects/helloworld10/helloworld10/Main.cs:14 

Upvotes: 2

Views: 2325

Answers (4)

creatiive
creatiive

Reputation: 1093

I had this same problem. What fixed it for me was that my image was in Resources/Image.png. Once I changed this to Images/Image.png it worked. The folder seems to have to be called "Images".

Upvotes: 0

Mastro
Mastro

Reputation: 1497

I had this same problem as well. The error occurs when it can't find the image in question. This happens when A) something is spelled wrong, such as the image name (it's case sensitive), or the path is wrong and B) the file is not marked as "Content".

So everyone else already mentioned marking it as Content I'll just elaborate on file location. You can store it on the root or better to create a folder and call it anything you like. Then reference the image as

var image = UIImage.FromBundle ("FolderName/GoldenGate.jpg");

Upvotes: 0

gschmidlehner
gschmidlehner

Reputation: 31

Seems to bee a bug. The image must be placed in a folder, eg @"Images/GoldenGate.jpg" (and Build Action set to "Content")

Upvotes: 3

Geoff Norton
Geoff Norton

Reputation: 5056

Is the file in your project called "GoldenGate.jpg" ? Remeber that iOS devices are case sensitive, while the emulator is only case-aware. Have you also marked the file as content in your project?

Upvotes: 2

Related Questions