自己用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 谢谢。
解决方案 »
- 嵌套repeater中,子repeater取值问题(在子repeater的OnItemCommand时间中)
- 求助!!Webdings字体5和6对应的Unicode编码是多少?
- 【求助】搭建三层架构环境遇到疑问,请各位帮忙解决!
- javascript实现setInterval 输出自增数字?
- 求能把程序中的未使用的方法,参数列表的工具
- ObjectDataSource“ObjectDataSource1”未能找到带参数的非泛型方法“UpDate"
- 各位大侠,谁能看出这段代码如何错了啊?急用~在线等~
- 如何将不同数据库中的数据绑定到一个datagrid里面去?急用
- 请教一个问题
- 页面跟踪和页面调试是什么意思呢?
- 怎么让指定目录的图片不缓存到临时文件目录里。
- 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(){}捕获一下异常!!