我正在开发和应用于xamarin for android。有两个按钮用于上传Parse对象,另一个用于下载对象和显示图像。上传按钮工作正常。但我面临两个主要问题
首先:我在IEnumerable对象中获取null值。我附上了断点值的截图。
第二:当我试图显示对象时,我收到错误。我附上了显示错误的屏幕截图
上传按钮:
upbutton.Click += async delegate {
try {
byte[] myfile = System.IO.File.ReadAllBytes (path);
ParseFile file = new ParseFile ("imgfl.png", myfile);
await file.SaveAsync ();
// link your file object to your Parse object
ParseObject gameScore = new ParseObject ("GameScore");
gameScore ["score"] = 0001;
gameScore ["playerName"] = " Bob";
gameScore ["image"] = file;
await gameScore.SaveAsync ();
} catch (Exception e) {
System.Console.WriteLine (e);
}
};
下载按钮:
downbutton.Click+= async delegate {
var query = from GameScore in ParseObject.GetQuery("GameScore")
orderby GameScore.CreatedAt descending
select GameScore;
IEnumerable<ParseObject> results = await query.FindAsync();
//I am getting a null object result here
foreach (var obj in results)
{
ParseFile img = obj.Get<ParseFile>("image");
_imageView.SetImageURI(img.Url);
//error here
}
};
答案 0 :(得分:0)
您的GameScore
行之一可能没有设置image
属性,对于该行,您的null
结果会img
变量。
另请注意,在您的下载按钮代码中,您将获得每一行并继续为每一行调用_imageView.SetImageURI(img.Url)
行,可能会反复替换该值。
如果您只想要一行,则可能希望进行FirstAsync()
调用,而不是FindAsync()
。