2011-04-13 61 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"); 


    } 
相關問題