从Parse和Display下载ParseObject

时间:2014-06-25 16:19:00

标签: c# android xamarin xamarin.android parse-platform

我正在开发和应用于xamarin for android。有两个按钮用于上传Parse对象,另一个用于下载对象和显示图像。上传按钮工作正常。但我面临两个主要问题

首先:我在IEnumerable对象中获取null值。我附上了断点值的截图。 BreakPoint null object

第二:当我试图显示对象时,我收到错误。我附上了显示错误的屏幕截图

error

上传按钮:

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
            }


        };

1 个答案:

答案 0 :(得分:0)

您的GameScore行之一可能没有设置image属性,对于该行,您的null结果会img变量。

另请注意,在您的下载按钮代码中,您将获得每一行并继续为每一行调用_imageView.SetImageURI(img.Url)行,可能会反复替换该值。

如果您只想要一行,则可能希望进行FirstAsync()调用,而不是FindAsync()