这是我的代码。我得到数据,但name1返回空值。我想在textView和imageview中以数据集的形式显示从webservice获取的数据。你能帮帮我吗?
执行第name1.SetText(productName);
行时
错误获取是
未处理的例外:
下面的System.NullReferenceException:未将对象引用设置为实例 一个对象。发生
是存储的局部变量。
名称值类型
detailOfproduct" botle是"串
fdetail" botle是"串
fimage" iVBORw0"串
fname" Bottle"串
imageproduct" iVBORw0"串
productName" Bottle"串
name1(null)
Android.Widget.TextView详细信息(null)
Android.Widget.TextView
WebReferencec.WebService add = new WebReferencec.WebService();
DataSet result = add.getData("bottle");
DataTable dt = result.Tables["product"];
//DataRow row = dt.NewRow();
fname = dt.Rows[0]["name"];
fdetail= dt.Rows[0]["detail"];
fimage = dt.Rows[0]["image"];
// dt.Rows.Add(row);
imageproduct = Convert.ToString(fimage);
productName = Convert.ToString(fname);
detailOfproduct = Convert.ToString(fdetail);
byte[] ba = Convert.FromBase64String(imageproduct);
using (var stream = new MemoryStream(ba))
{
ImageView image = FindViewById<ImageView>(Resource.Id.ivgallery);
TextView name1 = FindViewById<TextView>(Resource.Id.tvname);
TextView detail = FindViewById<TextView>(Resource.Id.tvdetail);
Bitmap bitmap = BitmapFactory.DecodeByteArray(ba, 0, ba.Length);
RunOnUiThread(() =>
{
image.SetImageBitmap(bitmap);
name1.SetTextKeepState( productName);
detail.SetTextKeepState( detailOfproduct);
}
);
}
答案 0 :(得分:0)
当我通过放置imageview和text视图声明变量图像名称和细节时,变量不在字符串中。所以我不得不把var infront转换成字符串。
Var image = FindViewById(Resource.Id.ivgallery);
Var name1 = FindViewById(Resource.Id.tvname);
var detail = FindViewById(Resource.Id.tvdetail);