应用程序停止响应,没有明显的原因 - c#

我的骰子滚轴应用程序包含7个文本框(三对“骰子号”和“骰子类型”对以及一个奖励)和一个按钮。我打算分别阅读每对文本框,如果它不包含有效数字(由于应用程序原因,'fate'和'%'被读作数字),它将忽略它。

问题是,当我没有在“否”之一中输入有效数字时。应用程序停止响应,并最终返回到加载页面。

请注意,我已经分别测试了每种方法。

这是代码:

namespace DiceRoller
{
public sealed partial class MainPage : DiceRoller.Common.LayoutAwarePage
{
    public MainPage()
    {
        this.InitializeComponent();
    }

    Random r = new Random();

    //regular, untouched basic page code here

    private void btnRoll1_Click(object sender, RoutedEventArgs e)
    {
        //the problem is with the number boxes.
        List<int>[] results = new List<int>[3];
        if (!(ReadInput(textBoxNumber1.Text) == 0 || ReadInput(textBoxType1.Text) == 0))
        {
            results[0] = Roll(ReadInput(textBoxType1.Text), ReadInput(textBoxNumber1.Text));
        }
        if (!(ReadInput(textBoxNumber2.Text) == 0 || ReadInput(textBoxType2.Text) == 0))
        {
            results[1] = Roll(ReadInput(textBoxType2.Text), ReadInput(textBoxNumber2.Text));
        }
        if (!(ReadInput(textBoxNumber3.Text) == 0 || ReadInput(textBoxType3.Text) == 0))
        {
            results[2] = Roll(ReadInput(textBoxType3.Text), ReadInput(textBoxNumber3.Text));
        }
        textBlockOutput1.Text = "Results:" + String.Join(", ",results[0]) + ", " + String.Join(", ", results[1]) + ", " + String.Join(", ", results[2]) + System.Environment.NewLine + "Total:" + ((results[0].Sum() + results[1].Sum() + results[2].Sum() + ReadInput(textBoxBonus.Text)).ToString());
    }

    //METHODS

    private int ReadInput(string input) //tested
    {
        int returnValue = 0;
        if (int.TryParse(input, out returnValue)) ; //the 'out' will make sure that the number has passed
        else if (input == "%") returnValue = 100;
        else if (input.ToLower() == "fate") returnValue = 6;
        else if (input == "") ;
        else textBlockOutput1.Text = "Error: All text boxes should contain a number,       the strings '%', 'Fate'(not case sensitive) or to be blank";
        return returnValue;
    }

    private int Roll(int diceType) //tested
    {
        return r.Next(diceType - 1) + 1;
    }

    private List<int> Roll(int diceType, int diceNumber)//tested
    {
        List<int> results = new List<int>();
        for (int i = 1; i <= diceNumber; i++) results.Add(Roll(diceType));//if one of the no. textboxes is read as '0', this couln't operate
        return results;
    }
}

}

-提前感谢帮手

编辑:我按照注释中的建议使用调试器进行了查看(谢谢),错误为“值不能为空”。但是什么值呢?它没有提供任何线索。再次感谢。

参考方案

您已制作了一系列列表

List<int>[] results = new List<int>[3];

你真正想要的是
List<int>() results = new List<int>();

然后使用results.Add(Roll());为此添加值

您将需要进行更多调试,以确保最终文本集有3个值

编辑2
这支持了理论

编辑..

刚意识到您有2种滚动方法,
在设置它们之前,您应该将其初始化为sucn

for(int i = 0; i < 3; i++)
{
results[i] = new List<int>();
}

当回复有时是一个对象有时是一个数组时,如何在使用改造时解析JSON回复? - java

我正在使用Retrofit来获取JSON答复。这是我实施的一部分-@GET("/api/report/list") Observable<Bills> listBill(@Query("employee_id") String employeeID); 而条例草案类是-public static class…

改造正在返回一个空的响应主体 - java

我正在尝试使用Retrofit和Gson解析一些JSON。但是,我得到的响应机构是空的。当我尝试从对象中打印信息时,出现NullPointerException。我确保URL正确,并且我也确保POJO也正确。我正在使用jsonschema2pojo来帮助创建POJO类。这是我要解析的JSON{ "?xml": { "@versi…

json数组,其中in数组返回错误?坏字符串 - javascript

我将json字符串文件解析为python,并且始终返回error。我使用了在线json格式化程序和验证器,它们也返回错误,因此我需要帮助使我的json正确并告诉我错误 [{ "sentence_id": "TR.00001", "sentence": { "text": …

Sublime Text 3 Linter问题 - javascript

上周,我发现了这个很棒的文本编辑器“ Sublime Text 3”,我喜欢这些插件。除了SublimeLinter插件和为其添加语言特定棉絮的插件,其他所有东西都可以正常工作。我在与PHP和JavaScript配合使用时遇到问题:PHP确实可以工作,但是我不知道如何使JavaScript正常工作。对于php,我所做的是转到Pref> pac set&…

在PHP中使用long int - php

我正在尝试此方法,但无法存储较大的价值$var = rand(100000000000000,999999999999999); echo $var; // prints a 9 digit value(largest possible) 如何获得期望值? 参考方案 PHP整数通常为32位。其他软件包提供了更高精度的整数:http://php.net/man…