无法使用imageview
本文关键字:imageview | 更新日期: 2023-09-27 17:51:21
我有一个非常简单的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
似乎是一个bug。图像必须放在文件夹中,例如@"Images/GoldenGate.jpg"
(和Build Action设置为"Content"
)
项目中的文件是否名为"GoldenGate.jpg" ?请记住,iOS设备是区分大小写的,而模拟器只区分大小写。您是否也将该文件标记为项目中的内容?
我也有同样的问题。当它找不到有问题的图像时发生错误。当A)某些东西拼写错误时,例如图像名称(区分大小写),或者路径错误,并且B)文件未标记为"Content"时,就会发生这种情况。
所有人都提到了标记为内容,我将详细说明文件位置。您可以将其存储在根目录中,或者创建一个文件夹,并将其命名为您喜欢的任何名称。然后将图像引用为
var image = UIImage。FromBundle("FolderName/GoldenGate.jpg");
我也遇到过同样的问题。为我修复它的是,我的图像在资源/图像。png。一旦我将其更改为Images/Image.png,它就工作了。这个文件夹应该命名为"Images"