如何解决对象引用未设置为我的代码中的对象实例 [英] How Can I Solve Object Reference Not Set To An Instance Of An Object In My Code

查看:57
本文介绍了如何解决对象引用未设置为我的代码中的对象实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

private void CreateBarGraph()
{
   string strCaption = "Attendence Performance Percentage wise";
   string strSubCaption = "For DPS2013-2014";
   string xAxis = "Name";
   string yAxis = "Percentage";

   //strXML will be used to store the entire XML document generated
   string strXML = null;

   //Generate the graph element
   strXML = @"
pieSliceDepth='30' formatNumberScale='0'
xAxisName='" + xAxis + @"' yAxisName='" + yAxis + @"' rotateNames='1'
>";
    
    int i = 0;
    dt = (DataTable)Session["row"];
    foreach (DataRow dr2 in dt.Rows)
    {
       strXML += " i++";
    }

    //Finally, close element
    strXML += "";

    FCLiteral2.Text = FusionCharts.RenderChartHTML("FusionCharts/FCF_Column3D.swf", // Path to chart's SWF
                                                            "", // Leave blank when using Data String method
                                                            strXML, // xmlStr contains the chart data
                                                            "mygraph1", // Unique chart ID
                                                            GraphWidth, GraphHeight, // Width & Height of chart
                                                            false
                                                            );
}

推荐答案

您可以通过阅读这个 [ ^ ]或 this [ ^ ]。



此错误消息是告诉你需要提供一个存在的变量对象或至少有一个
You can solve this problem by reading this[^] or this[^].

This error message is telling you that you need to provide a variable object that exists or atleast has a value.


我们无法确切地说出来,部分是因为你没有告诉我们哪一行给你问题,部分是因为我们无法运行你的代码。但......最可能的原因不在于该代码。



我怀疑问题出现在这里:

We can't tell exactly, partly because you don;t tell us which line gives you the problem, and partly because we can't run your code. But...the most likely reason is not in that code.

I suspect that the problem occurs here:
foreach (DataRow dr2 in dt.Rows)

并由此引起:

And is "caused" by this:

dt = (DataTable)Session["row"];

如果你的Session没有包含row的值,则返回null,当你尝试使用 dt.Rows 时,它将会结果抛出一个空引用异常。



至于为什么你的Session什么都没有,我可以说 - 你需要先看看你放的是什么进入会议并仔细检查该部分。

我们不能为你做到这一点!

If your Session contains no value for "row" is will return null, and when your try to use dt.Rows it will throw a null reference exception as a result.

By as to why your Session contains nothing, I can;t say - you need to start by looking at what you put into the Session and check that part very carefully.
We can't do that for you!


这篇关于如何解决对象引用未设置为我的代码中的对象实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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