Quiz Error: XML /System.NullReferenceException

Posted on 2008-11-04
Last Modified: 2013-11-08

I am trying to use Enrico's online quiz script but keep getting an error.

 The page loads in for the first time ok with the question showing but when i click the submit button I get this error:


Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

Line 42:
Line 43:       'Correct answer?
Line 44:       If rblAnswer.SelectedItem.Value = ViewState("CorrectAnswer") Then
Line 45:             intScore += 1
Line 46:             arrAnswerHistory.Add(0)

 What does this mean?  How do I fix it?



Question by:Tania_Farmer
    LVL 13

    Expert Comment

    Which line is throwing the exception ?
    Your problem be that arrAnswerHistory is null. If you set a break point there and run your page in debug you'll probably see that arrAnswerHistory=null and you try to use it anyway.
    LVL 14

    Accepted Solution

    check page view state is enabled
    if no, enable the page level viewstate

    <%@ Page EnableViewState="true" %>

    Author Comment

    That did it - thanks!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    Why do we like using grid based layouts in website design? Let's look at the live examples of websites and compare them to grid based WordPress themes.
    I've been asked to discuss some of the UX activities that I'm using with my team. Here I will share some details about how we approach UX projects.
    The viewer will learn how to count occurrences of each item in an array.
    The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now