如何解决这个错误:类型的未处理的异常“System.NullReferenceException”发生在DotTeach.exe [英] how do i fix this error :An unhandled exception of type 'System.NullReferenceException' occurred in DotTeach.exe

查看:417
本文介绍了如何解决这个错误:类型的未处理的异常“System.NullReferenceException”发生在DotTeach.exe的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

更多信息:未设置为一个对象的实例对象引用

Additional information: Object reference not set to an instance of an object.

我有这样的代码

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从文本框中的值和它们发送到数据的基础上,但我不断收到错误:

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:


未处理的异常'System.NullReferenceException'
发生在DotTeach.exe

An unhandled exception of type 'System.NullReferenceException' occurred in DotTeach.exe

更多信息:对象
引用不设置到
对象的实例

Additional information: Object reference not set to an instance of an object.

和Visual Studio中突出了行

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.

推荐答案

好,要获得的NullReferenceException 有一个的的下面是空:

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


  • TA

  • discussionQuestion

  • 网页

  • choiceA

  • choiceB

  • choiceC

  • choiceD

  • 提示

  • rightAnswerCbox

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

我的的是 TA ,但你应该能够找到出去要么记录或调试器。什么是意味着要指定一个非空值 TA

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?

这篇关于如何解决这个错误:类型的未处理的异常“System.NullReferenceException”发生在DotTeach.exe的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆