private List<InMemoryRandomAccessStream> undoStreamList;
InMemoryRandomAccessStream tempStream = new InMemoryRandomAccessStream();
await inkCanvas.InkPresenter.StrokeContainer.SaveAsync(tempStream);
undoStreamList.Add(tempStream);
state++;
此代码在倒数第二行返回NullReferenceException
,我该如何解决?
我也尝试将倒数第二行更改为undoStreamList.Add(new InMemoryRandomAccessStream);
,但它不起作用。
答案 0 :(得分:1)
看起来您的列表尚未初始化:
// Initialize this either inline or inside the constructor...
private List<InMemoryRandomAccessStream> undoStreamList = new List<InMemoryRandomAccessStream>();
InMemoryRandomAccessStream tempStream = new InMemoryRandomAccessStream();
await inkCanvas.InkPresenter.StrokeContainer.SaveAsync(tempStream);
undoStreamList.Add(tempStream);
state++;
这是该行抛出异常的唯一可能原因!