我该如何修复此错误:类型为“System.NullReferenceException”的未处理异常发生在 DotTeach.exe 中

发布于 2024-10-19 09:31:58 字数 1543 浏览 5 评论 0原文

附加信息:未将对象引用设置为对象的实例。

我有这段代码

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.exe

Additional 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

萌︼了一个春 2024-10-26 09:31:58

  • 好吧,要获得 NullReferenceException,以下其中一个为空:tadiscussionQuestion
  • 猜测
  • <
  • webPage choiceA choiceB choiceC choiceDhint rightAnswerCbox

code >ta,但您应该能够通过日志记录或在调试器中找到它。为 ta 分配一个非空值意味着什么?

这是总是失败(在这种情况下很容易诊断)还是只是有时失败?

Well, to get a NullReferenceException, one of the following is null:

  • ta
  • discussionQuestion
  • webPage
  • choiceA
  • choiceB
  • choiceC
  • choiceD
  • hint
  • rightAnswerCbox

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 to ta?

Is this always failing (in which case it'll be easy to diagnose) or only sometimes?

赢得她心 2024-10-26 09:31:58

当 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 ! )

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文