我有一个非常简单的monotouch应用程序,我试图在uiimageview中引用图像,但我没有成功。以下是代码清单和我不断得到的错误。请帮忙。我不知道我做错了什么。我已经仔细检查过GoldenGate.jpg是我项目的一部分
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)
{
}
}
}
但是,我收到以下错误。请帮帮我
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
答案 0 :(得分:3)
好像是个臭虫。图像必须放在一个文件夹中,例如@"Images/GoldenGate.jpg"
(并将构建操作设置为"Content"
)
答案 1 :(得分:2)
项目中的文件名为“GoldenGate.jpg”吗?请记住,iOS设备区分大小写,而模拟器只能识别案例。您是否还将文件标记为项目中的内容?
答案 2 :(得分:0)
我也有同样的问题。当它无法找到有问题的图像时会发生错误。当 A)拼写错误时会发生这种情况,例如图片名称(区分大小写),或路径错误且 B)文件是未标记为"内容"。
所以其他人都已经提到将其标记为内容我只是详细说明文件位置。您可以将其存储在根目录或更好的位置以创建文件夹并将其命名为您喜欢的任何内容。然后将图像引用为
var image = UIImage.FromBundle(" FolderName / GoldenGate.jpg");
答案 3 :(得分:0)
我有同样的问题。为我修复的是我的图像在Resources / Image.png中。一旦我将其更改为Images / Image.png就可以了。该文件夹似乎必须被称为“图像”。