帮助null引用异常

编程入门 行业动态 更新时间:2024-10-25 23:29:50
本文介绍了帮助null引用异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

美好的一天所有我创建一个对象,然后在该对象上使用方法,但我认为我的代码中有错误,任何人都可以帮助我

Good day all I create an object and then use a method on that object but I think I have an error in my code can anyone assist me

using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using Pastel.Evolution; using DD.Library; public partial class Default4 : System.Web.UI.Page { private Lib.cPastel objPastel; protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { objPastel.CreateGRV(648337); getting Null reference exception here void method only takes an int as an parameter }

推荐答案

你还没有创建 objPastel , you haven't create any instance of objPastel, //create new instance objPastel = new Lib.cPastel(); //then call the method objPastel.CreateGRV(648337);

如果您在其他地方创建 cPastel 的此实例在你的程序中,并且对着 objPastel ,你最好检查下面的null

if you creating this instance of cPastel somewhere else in your program and asigning to objPastel , then you better check for null like below

if(objPastel!=null) { objPastel.CreateGRV(648337); }

谢谢你这么多时间的编码有时候因为我们错过了小事而有了外面的观点 Thank you So much after hours of coding sometimes it helps to have an outside view because we miss the small things

更多推荐

帮助null引用异常

本文发布于:2023-11-17 05:18:35,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1608964.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:异常   null

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!