Lounge - System.NullReferenceException: Object reference not set to an instance of an object.

Asked By Ralph Naim on 16-Jun-12 04:39 AM

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 38:   private string PrepareStringForRendering(string str)

Line 39:   {

Line 40:     string[] lines = str.Split(new Char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);

Line 41:     StringBuilder preparedStr = new StringBuilder();

Line 42:     if (lines.Length > 0)


Can anyone help me with this one? The enterprise portal isn't opening it's giving this error.
Vikram Singh Saini replied to Ralph Naim on 16-Jun-12 04:59 AM
The initialization of variable str failed in your code. And so is the error. Ensure that the str variable is getting initialized with value or is not null like as:

if(str!=null)
{
    string[] lines = str.Split(new Char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
}
Jitendra Faye replied to Ralph Naim on 18-Jun-12 07:28 AM
This problem comes when you try to get or set values from any  null object.

so before fetching or setting value first check that is it null or what.

check for object where you are getting error.