异常详细信息: System.NullReferenceException的问题

lanxing106 2008-06-27 12:26:04
怎么样做才可以不出这个异常,我是菜鸟,帮忙看一下
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections;

/// <summary>
/// Util 的摘要说明
/// </summary>
public class Util
{

private static ArrayList valueList = new ArrayList();
private static ArrayList countList = new ArrayList();

public Util()
{
//
// TODO: 在此处添加构造函数逻辑
//
}


//返回二维数组,供曲线图调用
public static string[][] readBgValueArray()
{
int arraySize=bgValueCount();
string[][] str = new string[arraySize][];
for (int i = 0; i < str.Length; i++)
{
str[i][0] = Convert.ToString(Math.Round((double)valueList[i],2));
str[i][1] = Convert.ToString(Math.Round((double)countList[i],2));
}

return str;
}

//计算正数存储大小
public static int bgValueZCount()
{
string value = "";
int j = 0;
int count = 0;
double d = 0.01;
while ( d <= 1)
{
value= Convert.ToString(Math.Round(d,2));
j = DBCommand.readBackGroundValueCount(value);
if (j > 0)
{
valueList.Add(d);
countList.Add(j);
count++;
}
d += 0.01;
}
return count;
}

//计算负数数存储大小
public static int bgValueFCount()
{
string value = "";
int j = 0;
int count = 0;
double d = -0.01;
while (d >= -1)
{
value = Convert.ToString(Math.Round(d, 2));
j = DBCommand.readBackGroundValueCount(value);
if (j > 0)
{
valueList.Add(d);
countList.Add(j);
count++;
}
d += -0.01;
}
return count;
}

//计算NULL存储大小
public static bool bgValueNullCount()
{
bool flag=false;
int count= DBCommand.readBackGroundValueCount("NULL");
if (count > 0)
{
valueList.Add("NULL");
countList.Add(count);
flag = true;
}
return flag;
}

//计算比值个数
public static int bgValueCount()
{
int zCount = bgValueZCount();
int fCount = bgValueFCount();
int nullCount = 0;
if (bgValueNullCount())
{
nullCount = 1;
}

return zCount + fCount + nullCount;
}
}
...全文
927 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
lanxing106 2008-07-02
  • 打赏
  • 举报
回复
恩 已经解决啦 哈哈
halk 2008-07-01
  • 打赏
  • 举报
回复
问题解决没?
lanxing106 2008-07-01
  • 打赏
  • 举报
回复
halk 给你加了100分 够意思吧
halk 2008-06-27
  • 打赏
  • 举报
回复
唉,算了免费解答吧
你想使用二维string数组是不?应该这么做:



string[,] str = new string[arraySize, 2];
for (int i = 0; i < str.Length; i++)
{
str[i, 0] = Convert.ToString(Math.Round((double)valueList[i],2));
str[i, 1] = Convert.ToString(Math.Round((double)countList[i],2));
}



其次,根据你的需要看,你把这个数组搞成string类型数组,简直是自找麻烦。
fsy123456accp 2008-06-27
  • 打赏
  • 举报
回复
单步调式一下阿啊,肯定可以找到问题的所在
wlovew 2008-06-27
  • 打赏
  • 举报
回复
看看你这个i值对应的list里面有没有值!!
lanxing106 2008-06-27
  • 打赏
  • 举报
回复
str[i][0] = Convert.ToString(Math.Round((double)valueList[i],2));
出错了
我不知道怎么给分
halk 2008-06-27
  • 打赏
  • 举报
回复
1、标出出问题的地方!
2、给分!

看了一半,至少在
//返回二维数组,供曲线图调用
public static string[][] readBgValueArray()
{
int arraySize=bgValueCount();
string[][] str = new string[arraySize][];
for (int i = 0; i < str.Length; i++)
{
str[i][0] = Convert.ToString(Math.Round((double)valueList[i],2));
str[i][1] = Convert.ToString(Math.Round((double)countList[i],2));
}

return str;
}
中,肯定会出现你说的错误。

110,533

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧