我有一个包含个人信息的表格视图。信息来自 textviews 并放入一个数组中,最后以 txt 文件的形式存储在磁盘上。当一个人选择一个条目来更新我读取文件的个人信息时,将数据放回数组中并希望用原始数据填充文本视图 这是我的问题陈述。我想用文件中的数据填充文本视图。
我可以选择此人,但收到 System.NullReferenceException: Object reference not set to an instance of an object。
我正在使用来自 Xamian 和其他人的示例来填充 tableview。我的程序由公共部分类 RegistrantScreen 组成:具有文本视图和其他控件的 UIViewController。我使用 xib 创建物理接口。我的公共类 registrantTableSource : UITableViewSource 具有常规方法 RowsinSection 和 RowSelected。我使用 RowSelected 作为方法来了解需要更新哪些人员数据。当我选择一个人时,RowSelected 会触发并开始处理。我将选定的人员索引号传回,然后读取文件并放入数组中。当我尝试使用数组数据填充文本视图时,我得到空引用异常。
以下是获取人员选择索引并传回其他类的两种方法。
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 和其他控件不为空的过程。任何帮助或指针表示赞赏。