【发布时间】: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;
}
}
我试图以最容易理解的方式解释这个问题。如果您能指出我的解决方案,将不胜感激。
【问题讨论】:
-
addValueToSingleCell是做什么的?作为旁注:当查看这样的错误时,您应该关注它发生的最深层次,其他一切都只是堆栈跟踪,向您显示导致那一刻的确切原因。 -
我们在开始时有一个空的数独字段。然后我们输入测试数据:
AddValueToSingleCell(5, new Tuple<int, int>(i, j))其中5是单元格的值,(i, j)- 它是坐标。我是编程新手,刚刚开始探索 WP8 平台。所以最深的层次对我来说是密封的。 -
您可以编辑您的代码以显示
AddValueToSingleCell的(相关)内容吗? -
准备好了。实际上这个方法只是调用了另外三个方法。所以我认为,问题在更深的地方。
-
您是否曾通过这些方法与文件系统进行交互?
标签: c# windows-phone-8 access-violation