求助·!刚学出问题了,大神帮看看
asp吧
全部回复
仅看楼主
level 1
a4617424687 楼主
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Collections;
public partial class _1 : System.Web.UI.Page
{
ArrayList count = new ArrayList();
protected void Page_Load(object sender, EventArgs e)
{
getvote();
}
protected void getvote()
{
string file = Server.MapPath("tp.txt");
StreamReader sr = File.OpenText(file);
while(sr.Peek()!=-1)
{
string str=sr.ReadLine();
string[]strtp=str.Split('|');
foreach (string ss in strtp)
count.Add(int.Parse(ss));
}
sr.Close();
}
protected void putvote()
{
string aa = Server.MapPath("tp.txt");
if (File.Exists(aa))
{
StreamWriter se = new StreamWriter(aa,false);
string str = count[0].ToString();
for(int i=1;i<count.Count;i++)
str+="|"+count[i].ToString();
}
}
protected void Button2_Click(object sender, EventArgs e)
{
getvote();
Label2.Text = "各候选人票数:<br/>";
for (int i = 0; i < RadioButtonList1.Items.Count; i++)
{
Label2.Text += RadioButtonList1.Items[i].Value + ": " +count[i]+ "票" + "<br/>";
}
}
}
2015年04月22日 11点04分 1
level 1
a4617424687 楼主
“/投票”应用程序中的服务器错误。索引超出范围。必须为非负值并小于集合大小。
参数名: index说明: 执行当前 Web 请求期间,出现未经处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.ArgumentOutOfRangeException: 索引超出范围。必须为非负值并小于集合大小。
参数名: index
源错误:
行 46: for (int i = 0; i < RadioButtonList1.Items.Count; i++)行 47: {行 48: Label2.Text += RadioButtonList1.Items[i].Value + ": " +count[i]+ "票" + "<br/>";行 49: }行 50: }
源文件: c:\Users\Administrator\Desktop\投票\1.aspx.cs 行: 48
堆栈跟踪:
[ArgumentOutOfRangeException: 索引超出范围。必须为非负值并小于集合大小。参数名: index] System.Collections.ArrayList.get_Item(Int32 index) +10895768 _1.Button2_Click(Object sender, EventArgs e) in c:\Users\Administrator\Desktop\投票\1.aspx.cs:48 System.Web.UI.WebControls.Button.OnClick(EventArgs e) +9628634 System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +103 System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10 System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +35 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1724
2015年04月22日 11点04分 2
1