开发者

how do i fix this error :An unhandled exception of type 'System.NullReferenceException' occurred in DotTeach.exe

开发者 https://www.devze.com 2023-02-13 06:24 出处:网络
Additional information: Object reference not set to an instance of an object. I have this code DotTeachDataSet ds;

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 w开发者_开发知识库orking

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.


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?


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号