4天前我遇到了这个错误,并决定跳过并继续我的应用程序,但我还没有解决方案。我在我的适配器中将此错误System.InvalidCastException: Object must implement IConvertible
扩展到我的GetView function
中的baseAdapter。
我该怎么做才能解决这个问题?我该如何实施IConvertible?
适配器
class LocationAdapter: BaseAdapter
private JavaList<LocationFinder>findLocation;
public override View GetView(int position, View convertView, ViewGroup parent)
{
LayoutInflater inflater = (LayoutInflater)comment.BaseContext.GetSystemService(Context.LayoutInflaterService);
View itemView = inflater.Inflate(Resource.Layout.Data,null);
Name= itemView.FindViewById<TextView>(Resource.Id.getName);
Level = itemView.FindViewById<TextView>(Resource.Id.getLevel);
Date = itemView.FindViewById<TextView>(Resource.Id.getDate);
Name.Text = findLocation[position].Name;//error points here
Level.Text = findLocation[position].Level;
Date.Text = findLocation[position].Dates;
return itemView;
}
public override int Count
{
get
{
return findLocation.Count;
}
}
public override Java.Lang.Object GetItem(int position)
{
return position;
}
public override long GetItemId(int position)
{
return position;
}
LocationFinder
class LocationFinder
{
public string Name { get; set; }
public string Location { get; set; }
public string Dates { get; set; }
public LocationFinder()
{
}
public LocationFinder(string Name, string Location){
this.Name = Name;
this.Location = Location;
Dates = DateTime.Now.ToString("yyyy MMMMM dd);
}
}
答案 0 :(得分:1)
您从Firebase提取的LocationFinder对象是以Java.Objects形式出现的。无效的强制转换即将到来,因为您尝试对Java.Objects进行操作,就好像它们是LocationFinder对象一样。我建议将它们从你的JavaList
或更好的方式投出来,然后在它们进入List
时进行投射。
我不是哪种铸件最好的专家,但其中一种应该有用。
findLocation.Add(objectFromFirebase as LocationFinder);
findLocation.Add((LocationFinder)objectFromFirebase);
LocationFinder temp = (LocationFinder)findLocation[position];
LocationFinder temp = findLocation[position] as LocationFinder;