2011-04-13 59 views
0

请帮助我。这里是我的代码尝试从会话中存储的arraylist中检索值时出现问题

ArrayList arrValues = new ArrayList(); 
arrValues = (ArrayList)Session["ArrValues"]; 

string CustName, Addr1, Addr2, City, State, Country, Pin, Email,Order,CustToken; 
string SName, SAddr1, SAddr2, SCity, SState,SPin, SCountry;   

CustName = arrValues[1].ToString().Trim(); 

据thrwoing一个“NullReference excption”,而试图让CustName从存储在会话中的ArrayList中的值。下面的链接查看视频

http://www.talash.com/testingvideo/2011-03-18_0958_Payment_Gateway_Problem.swf

+0

你不应该intitialize一个新的ArrayList 'ArrayList arrValues = new ArrayList();'。当您的会话值为空时,您不会避免NullReferenceException,但会导致与此代码混淆。 – 2011-04-13 11:53:05

回答

0

的问题是,您的会话变量不存在。 arrValues为空。你需要看看你为什么失去你的会话变量。

您是否试图从页面或模块中获取此值? 如果您使用HttpModule,则会话在任何时候都不可用,并且可能会话对象为空。

0

因为您的会话变量未设置任何值的先前那为什么ü得到的是否是error.make该代码安全,将其置于樱雪是这样的..

if(Session[Arrvalues"]!=null) 
{ 

    //your block of code// 

} 
else 
{ 
    Response.Redirect("to_the_page_where_this_session_variable_is_set.aspx"); 


    } 
相关问题