问题描述
FFImageLoading 有一个奇怪的问题.编译器不显示任何错误,但是当应用程序在设备上启动时,抛出异常:System.NullReferenceException.
I've got a strange problem with FFImageLoading. Compiler don't show any error, but while application is starting on device, there is thrown an exception:System.NullReferenceException.
代码:
C#
private void setUserImage()
{
ImageService.Instance.Initialize();
imgThunbailUsername = FindViewById<ImageViewAsync>(Resource.Id.imgDisplay);
string url = @"https://lh4.googleusercontent.com/-Lfgi-xEMwuk/VNWoy8EDWcI/AAAAAAAAACk/rwsluNfhSZY/w1486-h832-no/photo.jpg";
ImageService.Instance.LoadUrl(url)
.Retry(3, 200)
.DownSample(60, 60)
.Into(imgThunbailUsername); // compiler points here with an exception
}
XML
<FFImageLoading.Views.ImageViewAsync
android:id="@+id/imgDisplay"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="fitCenter" />
如果您提供 Xamarin 中的任何提示、想法或什至另一个用于图像的好工具,我将不胜感激.
I'd be thankful for any tip, idea, or even another good tool for images in Xamarin.
推荐答案
好的,我知道出了什么问题.下面的 XML 不直接在 ViewModel 下.
Okay, I found out what's wrong. XML below is not directly under ViewModel.
<FFImageLoading.Views.ImageViewAsync
android:id="@+id/imgDisplay"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="fitCenter" />
里面调用了那边的XML
XML over there is called inside
<android.support.design.widget.NavigationView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="@android:color/white"
android:id="@+id/nav_view"
app:headerLayout="@layout/drawer_header" <!-- here -->
app:menu="@menu/navmenu" />
</android.support.v4.widget.DrawerLayout>
所以在这种情况下,我必须正确调用视图:
So in this case I have to call properly view:
View headerLayout = navigationView.InflateHeaderView(Resource.Layout.drawer_header);
等使用 FindViewById
之类的:
imgThunbailUsername = headerLayout.FindViewById<ImageViewAsync>(Resource.Id.imgDisplay);
所以我需要做的就是使用 InflateHeaderView
获取一个 View headerlayout
.
So all I need to do is just get a View headerlayout
with InflateHeaderView
.
这篇关于Xamarin Android FFImageLoading ImageService.Instance.LoadUrl() System.NullReferenceException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!