我该如何修复此错误:类型为“System.NullReferenceException”的未处理异常发生在 DotTeach.exe 中
附加信息:未将对象引用设置为对象的实例。
我有这段代码
DotTeachDataSet ds;
DotTeachDataSetTableAdapters.QuestionsTableAdapter ta;
private void button1_Click(object sender, RoutedEventArgs e)
{
ta.CreateQuestion(discussionQuestion.Text, webPage.Text, choiceA.Text, choiceB.Text, choiceC.Text, choiceD.Text, hint.Text, rightAnswerCbox.Uid);
ta.Fill(ds.Questions);
}
,我用它来尝试从 xaml 中的文本框中获取值并将它们发送到数据库,但我不断收到错误:
未处理的类型异常 '系统.NullReferenceException' 发生在DotTeach.exe
附加信息:对象 未设置对实例的引用 对象。
视觉工作室突出显示了这条线
ta.CreateQuestion(discussionQuestion.Text, webPage.Text, choiceA.Text, choiceB.Text, choiceC.Text, choiceD.Text, hint.Text, rightAnswerCbox.Uid);
有人知道我可以尝试什么吗?
我摆脱了错误消息,但它仍然没有做我需要它做的事情。我试图让它在单击按钮时将数据添加到数据库。这是我正在使用的功能,它不起作用
private void button1_Click(object sender, RoutedEventArgs e)
{
DotTeach.DotTeachDataSet dotTeachDataSet = ((DotTeach.DotTeachDataSet)(this.FindResource("dotTeachDataSet")));
DotTeach.DotTeachDataSetTableAdapters.QuestionsTableAdapter dotTeachDataSetQuestionsTableAdapter = new DotTeach.DotTeachDataSetTableAdapters.QuestionsTableAdapter();
//ADD THE QUESTION TO THE DATA BASE
dotTeachDataSetQuestionsTableAdapter.CreateQuestion(discussionQuestion.Text, webPage.Text, choiceA.Text, choiceB.Text, choiceC.Text, choiceD.Text, hint.Text, rightAnswer.Text);
}
我什至不知道还能尝试什么。
Additional information: Object reference not set to an instance of an object.
I have this code
DotTeachDataSet ds;
DotTeachDataSetTableAdapters.QuestionsTableAdapter ta;
private void button1_Click(object sender, RoutedEventArgs e)
{
ta.CreateQuestion(discussionQuestion.Text, webPage.Text, choiceA.Text, choiceB.Text, choiceC.Text, choiceD.Text, hint.Text, rightAnswerCbox.Uid);
ta.Fill(ds.Questions);
}
That Im using to try to get the values from text boxes in a xaml and send them to a data base but I keep getting the error:
An unhandled exception of type
'System.NullReferenceException'
occurred in DotTeach.exeAdditional information: Object
reference not set to an instance of an
object.
and visual studio highlights the line
ta.CreateQuestion(discussionQuestion.Text, webPage.Text, choiceA.Text, choiceB.Text, choiceC.Text, choiceD.Text, hint.Text, rightAnswerCbox.Uid);
Does anyone have any ideas what i could try?
I got rid of the error message but it's still not doing what I need it to do. I'm trying to get it to add data to a database when the button is clicked. Heres the function I'm using thats not working
private void button1_Click(object sender, RoutedEventArgs e)
{
DotTeach.DotTeachDataSet dotTeachDataSet = ((DotTeach.DotTeachDataSet)(this.FindResource("dotTeachDataSet")));
DotTeach.DotTeachDataSetTableAdapters.QuestionsTableAdapter dotTeachDataSetQuestionsTableAdapter = new DotTeach.DotTeachDataSetTableAdapters.QuestionsTableAdapter();
//ADD THE QUESTION TO THE DATA BASE
dotTeachDataSetQuestionsTableAdapter.CreateQuestion(discussionQuestion.Text, webPage.Text, choiceA.Text, choiceB.Text, choiceC.Text, choiceD.Text, hint.Text, rightAnswer.Text);
}
I'm not even sure what else to try.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我
NullReferenceException
,以下其中一个为空:tadiscussionQuestioncode >ta,但您应该能够通过日志记录或在调试器中找到它。为
ta
分配一个非空值意味着什么?这是总是失败(在这种情况下很容易诊断)还是只是有时失败?
Well, to get a
NullReferenceException
, one of the following is null:My guess would be
ta
, but you should be able to find that out either with logging or in the debugger. What's meant to be assigning a non-null value tota
?Is this always failing (in which case it'll be easy to diagnose) or only sometimes?
当 VS 突出显示 debug 中的行时,为什么不尝试将鼠标放在 Jon 提到的每一项上并查看调试信息告诉我们什么。识别哪些项目为 null,然后调查为什么它为 null。(一定是有原因的!)
When VS highlights the line in debug , why not try placing your mouse over each one of the items Jon has mentioned and look what the debug info tells.Identify which item(s) is(are) null and then investigate why thats null.( There must be a reason ! )