无法使用图像视图
我有一个非常简单的单点触控应用程序,我试图在 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
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
看来蜜蜂是个虫子。图像必须放置在一个文件夹中,例如
@"Images/GoldenGate.jpg"
(并且构建操作设置为"Content"
)Seems to bee a bug. The image must be placed in a folder, eg
@"Images/GoldenGate.jpg"
(and Build Action set to"Content"
)您的项目中的文件是否名为“GoldenGate.jpg”?请记住,iOS 设备区分大小写,而模拟器仅区分大小写。您是否也将该文件标记为项目中的内容?
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?
我也有同样的问题。当找不到有问题的图像时,就会发生错误。当A)某些内容拼写错误(例如图像名称(区分大小写))或路径错误并且B)文件未标记为“时,就会发生这种情况内容”。
所以其他人都已经提到将其标记为内容,我将详细说明文件位置。您可以将其存储在根目录中,或者更好地创建一个文件夹并将其命名为您喜欢的任何名称。然后将图像引用为
var image = UIImage.FromBundle ("FolderName/GoldenGate.jpg");
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");
我也有同样的问题。对我来说解决这个问题的是我的图像位于 Resources/Image.png 中。一旦我将其更改为 Images/Image.png,它就起作用了。该文件夹似乎必须命名为“Images”。
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".