错误 - >>你调用的对象是空的。 [英] ERROR ->> Object reference not set to an instance of an object.

查看:60
本文介绍了错误 - >>你调用的对象是空的。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在开发一个asp.net C#项目,

执行时,我收到错误并被重定向到下一页
'/''应用程序中的
服务器错误。

对象引用未设置为对象的实例。

描述:执行期间发生未处理的异常当前的网络请求。请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息。



异常详细信息:System.NullReferenceException:对象引用未设置为对象的实例。



来源错误:



第186行:clsRoomTemplate_DAL _clsRoomTemplate_DAL = new clsRoomTemplate_DAL();

第187行:DataTable dtCustomerSelectedItem = _clsRoomTemplate_DAL.PopulateCustomerSelectedItem();

第188行:if(dtCustomerSelectedItem.Rows.Count> 0)

第189行:{

第190行://字符串ImagePath = @ /图片/ sofa1.jpg; //你的形象路径





请帮助

谢谢

Hi,
I am working on a asp.net C# project,
On executing, I get an error and am redirected to the following page
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:

Line 186: clsRoomTemplate_DAL _clsRoomTemplate_DAL = new clsRoomTemplate_DAL();
Line 187: DataTable dtCustomerSelectedItem = _clsRoomTemplate_DAL.PopulateCustomerSelectedItem();
Line 188: if (dtCustomerSelectedItem.Rows.Count > 0)
Line 189: {
Line 190: // string ImagePath = @"/Images/sofa1.jpg"; //Your Image Path


Kindly help
thanks

推荐答案

检查可空性



Check for nullability

clsRoomTemplate_DAL _clsRoomTemplate_DAL = new clsRoomTemplate_DAL();
if(_clsRoomTemplate_DAL != null)
{
 // your code
}
else
{
// handle exception
}





希望有所帮助。



Hope that helps.


DataTable dtCustomerSelectedItem = _clsRoomTemplate_DAL.PopulateCustomerSelectedItem();
if (dtCustomerSelectedItem.Rows.Count > 0)
{
       string ImagePath = @"~/Images/sofa1.jpg"; //Your Image Path 
}


这篇关于错误 - >>你调用的对象是空的。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆