帮助null引用异常 [英] Help with null reference exception

查看:107
本文介绍了帮助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

    }

推荐答案

你还没有创建<$ c的任何实例$ c> 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引用异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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