【问题标题】:System.AccessViolationException issue on Windows Phone 8Windows Phone 8 上的 System.AccessViolationException 问题
【发布时间】:2014-09-26 04:46:33
【问题描述】:

在开发 WindowsPhone8 应用程序时遇到“System.AccessViolationException”问题,不知道如何处理。这里是GitHub repo

当应用程序尝试访问(分配值 5)int 类(“SudokuCell”)中的类(“SudokuSection”)的对象(“值”)字段(“SudokuField”)时出现异常)。

testSudokuField.AddValueToSingleCell(5, new Tuple<int, int>(i, j)); // class MainPage

public class SudokuField
{
    public SudokuSection[,] Sections;
    public SudokuHorizontal[] Horizontals;
    public SudokuVertical[] Verticals; 
    public bool solved;

public void AddValueToSingleCell(int value, Tuple<int, int> coords) // Item1 - horizontal, Item2 - vertical
    {
        var temp = InterpretCoordsForSection(coords);

        this.Sections[temp.Item1 - 1, temp.Item2 - 1].ChangeCellValue(value, temp.Item3, temp.Item4);
        this.Horizontals[coords.Item1 - 1].cells[coords.Item2 - 1].value = value;
        this.Verticals[coords.Item2 - 1].cells[coords.Item1 - 1].value = value;
    }

public class SudokuSection
{
    public SudokuCell[,] cells;

    // --------- Constructors
    public SudokuSection()
    {
        this.cells = new SudokuCell[3, 3];
        for (int i = 0; i < 3; i++)
            for (int j = 0; j < 3; j++)
                this.cells[i, j] = new SudokuCell();
    }

    public void ChangeCellValue(int value, int x, int y)
    {
        this.cells[x-1, y-1].ChangeValue(value);
    }
}

public class SudokuCell
{
    public int value; // Exect value of a cell
    public SortedSet<int> acceptableValues; // A of acceptable values of a single cell

    // --------- Constructors
    public SudokuCell() // Empty constructor
    {
        this.acceptableValues = new SortedSet<int>();
    }
    public SudokuCell(int value) // Constructor for a cell with an exect value
    {
        this.value = value;
    }

    // --------- Methods
    public void ChangeValue(int value)
    {
        this.value = value;
    }
}

我试图以最容易理解的方式解释这个问题。如果您能指出我的解决方案,将不胜感激。

Exception http://cs609829.vk.me/u33859447/docs/890ffbe19d74/question1.png?extra=UlBQBDfFTVi4oKt83aRDNfDrQcjh6AeNYv0aUQ1MmwDHWILYUR3EXmP82OylatDnm0BiT5wZBKYvqEcmQfLqLZX6bpJ7aCo

【问题讨论】:

  • addValueToSingleCell 是做什么的?作为旁注:当查看这样的错误时,您应该关注它发生的最深层次,其他一切都只是堆栈跟踪,向您显示导致那一刻的确切原因。
  • 我们在开始时有一个空的数独字段。然后我们输入测试数据:AddValueToSingleCell(5, new Tuple&lt;int, int&gt;(i, j)) 其中5 是单元格的值,(i, j) - 它是坐标。我是编程新手,刚刚开始探索 WP8 平台。所以最深的层次对我来说是密封的。
  • 您可以编辑您的代码以显示AddValueToSingleCell 的(相关)内容吗?
  • 准备好了。实际上这个方法只是调用了另外三个方法。所以我认为,问题在更深的地方。
  • 您是否曾通过这些方法与文件系统进行交互?

标签: c# windows-phone-8 access-violation


【解决方案1】:

绝对愚蠢的错误:testSudokuField = new SudokuField();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多