我有一个包含个人信息的tableview。信息来自textviews并放入一个数组中,最后以txt文件存储在磁盘上。 当一个人选择一个条目来更新个人信息时,我会读取该文件,将数据放回一个数组中, 想要用原始数据填充文本视图 这是我的问题陈述。我想用文件中的数据填充textviews。
我可以选择此人但接收System.NullReferenceException:对象引用未设置为对象的实例。
我正在使用Xamian和其他人的样本来填充tableview。 我的程序包含公共部分类RegistrantScreen:具有textviews和其他控件的UIViewController。我使用xib来创建物理接口。 我的公共类registrantTableSource:UITableViewSource有正常的方法RowsinSection和RowSelected。 我使用RowSelected作为方法来了解需要更新哪些人员数据。当我选择一个人时,RowSelected会触发并开始处理。我传回所选的人员索引号,然后读取文件并放入一个数组。当我尝试使用数组数据填充textview时,我得到了空引用异常。
以下是获取人选索引并传回其他类的两种方法。
public override void RowSelected (UITableView tableView, NSIndexPath indexPath)
{
//myPersonSelected = new RegistrantScreen (facility);
AnIndexSelected = true;
//need to read the fac file so we know if on site or off site for populating the boxes.
int person = indexPath.Row ;
//new UIAlertView("Row Selected", tableItems[indexPath.Row], null, "OK", null).Show();
tableView.DeselectRow (indexPath, true);
upDateOne (person);//jump over and get the file and fill an array for the person selected.
}//end of public override void RowSelected (UITableView tableView, NSIndexPath indexPath)
public void upDateOne(int rowPerson)//rowPerson is the selected index of registrants.
{
string facilityFolder =Environment.GetFolderPath (Environment.SpecialFolder.MyDocuments);
facilityFolder = System.IO.Path.Combine (facilityFolder , "Facilities");
facilityFolder = System.IO.Path.Combine (facilityFolder, "tmpFacility");
string facility = File.ReadAllText (facilityFolder);//has the name of the facility to open
string tmpRegistrants = facility.Replace ("fac", "par");//this holds the participants information.
facilityFolder =Environment.GetFolderPath (Environment.SpecialFolder.MyDocuments);
facilityFolder = System.IO.Path.Combine (facilityFolder , "Facilities");
tmpRegistrants = facility.Replace ("fac", "par");//this holds the participants information.
facilityFolder = System.IO.Path.Combine (facilityFolder , tmpRegistrants );//should be reading the par file now.
registrants = System.IO.File.ReadAllLines (facilityFolder);//this is the array for the selected participant.
//string [] personToUpdate = registrants[rowPerson];
//fillBoxes (Convert.ToString ( registrants[rowPerson]) );
//need to populate the text boxes next.
//need to check for commas again.
RegistrantScreen myPersonSelected;
myPersonSelected = new RegistrantScreen (facility );
//myPersonSelected .tableIndexChanged (rowPerson);
myPersonSelected.updateForOne(rowPerson );
;
}//end of public void upDateOne(int rowPerson)
这是我将数据传递给的地方。
public void updateForOne(int person)//fill the textboxes for one person.
{
facilityFolder=Environment.GetFolderPath (Environment.SpecialFolder.MyDocuments);
facilityFolder= System.IO.Path.Combine (facilityFolder, "Facilities");
facilityName= System.IO.Path.Combine (facilityFolder, Title);
facilityLines = System.IO.File.ReadAllLines (facilityName);//get the facility info to use for decision making.
string participantFile = facilityName.Replace ("fac", "par");
string [] participantList = System.IO.File.ReadAllLines (participantFile);//get all the participants
char [] deLimChars = { ',' };
string[] words = participantList[person].Split( deLimChars );
RegistrantScreen myTest = new RegistrantScreen (Title );
tbXXXXapproval.Text = words[0]; ****Null reference exception here.****
我认为我的对象被垃圾收集但是没有找到使我的textview和其他控件保持为空的过程。 任何帮助或指针都表示赞赏。