Problem with building and using Scintilla.NET
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."
ScinLis开发者_StackOverflowt.Add(scin);
tabControl1.TabPages.Add(tabp);
}
The problem is that you have not initialized ScinList
. Fields of a class are initialized to their default value, which in this case is null
.
You need to initialize it somewhere, either where it is declared...
public List<ScintillaNet.Scintilla> ScinList = new List<ScintillaNet.Scintilla>();
... or in the constructor ...
public CLASSNAMEHERE()
{
ScinList = new List<ScintillaNet.Scintilla>();
}
If this line actually does appear in your code, please edit your question with the code that does so.
The problem is you're not initializing ScinList
.
Change this:
public List<ScintillaNet.Scintilla> ScinList;
To this:
public List<ScintillaNet.Scintilla> ScinList = new List<ScintillaNet.Scintilla>();
Looks like you define your public field ScinList:
public List <ScintillaNet.Scintilla> ScinList;
but you never actually create a new list and assign it to your field:
public List <ScintillaNet.Scintilla> ScinList = new List<ScintillaNet.Scintilla>();
精彩评论