Android.Content.Res.Resources + NotFoundException

时间:2012-03-16 18:42:20

标签: xamarin.android

我有一个用Mono Android编写的应用程序,它有一个表单并在列表中显示数据。该应用程序工作正常。 但现在我正在尝试在布局中添加另一个字段:

   <TextView
            android:id="@+id/textDeliveryNo"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="12345"
            android:textStyle="bold"
            android:textColor="@color/title"
            android:textSize="20px"

   />

我相应地修改了活动以将此字段设置为其值:

 //Get our object for this position         
     var item = items[position];                        
     var view = (convertView ??                 
                context.LayoutInflater.Inflate(                 
                    Resource.Layout.DeliveriesListItem,                                parent,                  
                    false)) as LinearLayout;            

     //Find references to each subview in the list item's view          
     var imageItem = view.FindViewById(Resource.Id.imageItem) as ImageView;
     var textDeliveryNo = view.FindViewById(Resource.Id.textDeliveryNo) as TextView;
     var textDeliveryName = view.FindViewById(Resource.Id.textDeliveryName) as TextView;
     var textDeliveryAddress = view.FindViewById(Resource.Id.textDeliveryAddress) as TextView;
     var textDeliveryCityAndZip = view.FindViewById(Resource.Id.textDeliveryCityAndZip) as TextView;

     //Assign this item's values to the various subviews            
     imageItem.SetImageResource(item.Image);
  

错误行&gt; textDeliveryNo.SetText(item.DeliveryNo,TextView.BufferType.Normal);           textDeliveryName.SetText(item.LocationName,TextView.BufferType.Normal);           textDeliveryAddress.SetText(item.Address,TextView.BufferType.Normal);           textDeliveryCityAndZip.SetText(item.City +“,”+ item.PostalCode,TextView.BufferType.Normal);

调试器在ERROR LINE处停止并显示错误: Android.Content.Res.Resources + NotFoundException:

我试图清理,重建项目...重启VS 2010但没有。 如果我评论这一行它将编译,但它将显示“12345”或我在android:text属性上放置的任何内容。

我会帮助我获得任何帮助。 非常感谢你!

1 个答案:

答案 0 :(得分:1)

当您只想将其设置为字符串(恰好是数字)时,您正在使用的SetText的重载需要资源ID。

请改用:

txtDeliveryNo.Text = item.DeliveryNo.ToString ();

相关问题