|
|
Rank: มือสมัครเล่น Groups: Member
Joined: 9/3/2008 Posts: 27
|
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:
| An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. |
Stack Trace:
[NullReferenceException: Object reference not set to an instance of an object.]
CH.Button3_Click(Object sender, EventArgs e) +126
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +105
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +107
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1746
|
Server Error in '/nitisakp/cs' Application.
Object reference not set to an instance of an object.
Version Information: Microsoft .NET Framework Version:2.0.50727.1433; ASP.NET Version:2.0.50727.1433
|
|
 Rank: มือสมัครเล่น Groups: Member
Joined: 9/26/2008 Posts: 26 Location: BKK
|
น่าจะเกิดจากการ instantiate ลองดูว่ามี xx = new Panel() ใน public void xxx(xx){} หรือไม่ หากมีให้ย้ายไปที่ public xxxx() แทนครับ
|
|
Rank: มือสมัครเล่น Groups: Member
Joined: 9/3/2008 Posts: 27
|
ช่วยอธิบายอีกหน่อยได้ไหมครับ ลองยกตัวอย่างก็ได้ครับ พอดีเพิ่งหัดเขียนอะครับ เลยไม่ค่อยเข้าใจ
|
|
 Rank: มือสมัครเล่น Groups: Member
Joined: 9/26/2008 Posts: 26 Location: BKK
|
NullReferenceException เป็นเออเรอของการไปอ้างอิงถึง Method ,Property ,member ของตัวแปรออบเจ็กต์ที่ยังไม่ได้ชี้ไปยังออบเจ็กต์จริงๆ (ตัวแปรที่เป็น null) ยกตัวอย่างเช่น การประกาศตัวแปรแล้วไม่ได้กำหนดค่าเริ่มต้นหรือกำหนดเป็น null ต้องประกาศแบบนี้ครับ
string aaa="";
//not use string aaa =null;
แต่ผมไม่แน่ใจว่าจะตรงกับเออเรอที่ส่วนไหนของโค้ดคุณเนื่องจากไม่เห็นโค้ดตอนนี้แค่สันนิษฐานครับ
ลองบั้กค่า line CH.Button3_Click(Object sender, EventArgs e) +126 ดูเบื้องต้นก่อนครับครับ โดย Watch ดูว่า ตัวไหนเป็น null ซึ่งหากเป็นค่าว่างจะบอก <undefined value> ครับ
|
|
Rank: มือสมัครเล่น Groups: Member
Joined: 9/3/2008 Posts: 27
|
ขอบคุณมากครับ คือผมลองๆดูแล้ว และลองทดสอบแล้วครับ คือ ดวลาทดสอบที่เครื่องผมเองจะไม่มีปัญหาอะไร แค่พอไปลองที่ server มันจะเป็นแบบนั้นครับ ลองทดสอบแล้ว มันเกิดจาก Session ที่ผมกำหนดอะครับพอเวลามันไปที่ server แล้วมันเกิดเป็นค่าว่างอะครับ ทุกตัวเลย คือผมดึงข้อมูลจากฐานข้อมูลมาเก็บ ในSession อะครับ แต่เวลาที่ลองในเครื่องก็ไม่เห็นมีปัญหาเกิดจากอะไรหรอครับ รอคำชี้แนะครับ
|
|
 Rank: มือสมัครเล่น Groups: Member
Joined: 9/26/2008 Posts: 26 Location: BKK
|
ไม่ทราบว่าบน server file web.config มีการคอนฟิกเก็บ session เป็นแบบใดเหมือนกับlocal หรือปล่าวครับ เพราะปกติมีสามแบบ คือ
- InProc (default mode) เป็นการเก็บใน memory
- State Server เป็นการเก็บในเครื่งซึ่งสามารถแชร์ข้ามเครือ่งได้ ตัวอย่าง
<configuration>
<system.web>
<sessionState mode="StateServer"
stateConnectionString="tcpip=SampleStateServer:42424"
cookieless="false"
timeout="20"/>
</system.web>
</configuration>
- SQL Server เป็นการเก็บในดาต้าเบสเซิร์ฟเวอร์ ตัวอย่าง
<configuration>
<system.web>
<sessionState mode="SQLServer"
sqlConnectionString="Integrated Security=SSPI;data
source=SampleSqlServer;" />
</system.web>
</configuration>
|
|
|
Guest |