构建和使用 Scintilla.NET 时遇到的问题
我正在使用/构建 Scintilla.NET 并将项目切换到 .NET 2.0 以解决兼容性问题。
它有效,但是当我单击新选项卡按钮时,我收到一条错误消息:
对象引用未设置为 对象的实例。
问题出现在这段代码中:
ScintillaNet.Scintilla currentScin;
Stream Stream1;
public List <ScintillaNet.Scintilla> ScinList;
//Code for various events
private void New_Click(object sender, EventArgs e)
{
TabPage tabp = new TabPage();
ScintillaNet.Scintilla scin = new ScintillaNet.Scintilla();
scin.Dock = DockStyle.Fill;
scin.Margins[0].Width = 20;
scin.ConfigurationManager.CustomLocation = "My Styles";
scin.ConfigurationManager.Language = "lua";
scin.Parent = tabp;
// This line throws "Object reference not set to an instance of an object."
ScinList.Add(scin);
tabControl1.TabPages.Add(tabp);
}
I'm using/building Scintilla.NET and switched the project to .NET 2.0 for compatibility issues.
It works, but when I click the new tab button I get an error which says:
Object reference not set to an
instance of an object.
The problem occurs in this code:
ScintillaNet.Scintilla currentScin;
Stream Stream1;
public List <ScintillaNet.Scintilla> ScinList;
//Code for various events
private void New_Click(object sender, EventArgs e)
{
TabPage tabp = new TabPage();
ScintillaNet.Scintilla scin = new ScintillaNet.Scintilla();
scin.Dock = DockStyle.Fill;
scin.Margins[0].Width = 20;
scin.ConfigurationManager.CustomLocation = "My Styles";
scin.ConfigurationManager.Language = "lua";
scin.Parent = tabp;
// This line throws "Object reference not set to an instance of an object."
ScinList.Add(scin);
tabControl1.TabPages.Add(tabp);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
问题是您尚未初始化
ScinList
。类的字段被初始化为其默认值,在本例中为null
。您需要在某个地方初始化它,无论是在声明的地方...
...还是在构造函数中...
如果此行确实出现在您的代码中,请使用执行此操作的代码编辑您的问题。
The problem is that you have not initialized
ScinList
. Fields of a class are initialized to their default value, which in this case isnull
.You need to initialize it somewhere, either where it is declared...
... or in the constructor ...
If this line actually does appear in your code, please edit your question with the code that does so.
问题是您没有初始化
ScinList
。改变这个:
到这个:
The problem is you're not initializing
ScinList
.Change this:
To this:
看起来您定义了公共字段 ScinList:
但您从未真正创建一个新列表并将其分配给您的字段:
Looks like you define your public field ScinList:
but you never actually create a new list and assign it to your field: