自己用C#写了个系统,但访问网站动态页面(除首页静态生成外),经常会出现:
Object reference not set to an instance of an object.这样的错误,但重新刷新一下又能正常访问,查了代码也能正常运行,请大虾帮忙看下,谢谢,以下是一次出现的全部提示:Server Error in '/' Application.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: 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.]
ArticlesBean.GetRecordNum(Int32 id, Int32 classType) +105
ysys_index.Page_Load(Object sender, EventArgs e) +175
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
System.Web.UI.Control.OnLoad(EventArgs e) +91
System.Web.UI.Control.LoadRecursive() +74
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2207Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.1022重新刷新一下又会正常显示。网站是:http://www.18ys.cn 谢谢。
Object reference not set to an instance of an object.这样的错误,但重新刷新一下又能正常访问,查了代码也能正常运行,请大虾帮忙看下,谢谢,以下是一次出现的全部提示:Server Error in '/' Application.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: 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.]
ArticlesBean.GetRecordNum(Int32 id, Int32 classType) +105
ysys_index.Page_Load(Object sender, EventArgs e) +175
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
System.Web.UI.Control.OnLoad(EventArgs e) +91
System.Web.UI.Control.LoadRecursive() +74
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2207Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.1022重新刷新一下又会正常显示。网站是:http://www.18ys.cn 谢谢。
解决方案 »
- gridview单元格显示的值过长
- 设置 treeview 选中节点的样式。
- 网站开发中用到了大量的iframe的弊端
- 用Js脚本,如何取得文件域的文件名?
- 应聘asp.net 程序员需要懂哪些技术?
- 在DataList的itemtemplate模板中套用DataList,在被套用DataList的edititemtemplate中有个TextBox控件,请问怎样发现该控件.然后对其内容进
- 请教如何实现这个功能 最方便的方法 是否有此类控件
- 读取远程的Json内容不行,读取本地的却可以.内容一样的
- response.redirect的问题
- 说到底,万事入门难,往后请版主及各位朋友多加指教
- 怎么让指定目录的图片不缓存到临时文件目录里。
- ASP刷新问题
贴出这个方法的源代码
{
int recordNum = 0;
string sql = "select count(A.articleId) as num from articles as A,articleclass as B where A.isPassed=1 and A.fatherId=B.classId";
if (classType == 0)
{
sql = sql + " and A.fatherId=" + id;
}
else
{
sql = sql + " and A.classId=" + id;
} DataBase db = new DataBase();
SqlDataReader sdr = null;
sdr = db.getReader(sql);
sdr.Read();
recordNum = Convert.ToInt32(sdr["num"]);
sdr.Close();
return recordNum;
}程序在本地测试都能正常运行,vs调试是也是正常运行的,没错误提示。发布到网上,只是偶尔不同的页面会出现Object reference not set to an instance of an object.这种错误,但刷新下页面又能正常访问,并且没有任何错误,这种错误也是不定时的出现。
做try{}catch(){}捕获一下异常!!