I'm creating a simple Eclipse editor, this editor contains two pages, one of them is an editor that extends from AbstractDecoratedTextEditor
, then in my multipage editor class I'm adding the editor like this:
MyEditor myEditor = new MyEditor();
addPage(myEditor, myEditor.getEditorInput());
When I launch the application, the editor looks like this:
This is my class:
public class MyEditor extends AbstractDecoratedTextEditor {
public MyEditor() {
setSourceViewerConfiguration(new SourceViewerConfiguration());
setDocumentProvider(new FileDocumentProvider());
}
@Override
protected boolean isLineNumberRulerVisible() {
return true;
}
public void init(IEditorSite site, IEditorInput input) {
setSite(site);
setInput(input);
}
}
And this is the log:
java.lang.NullPointerException
at org.eclipse.ui.texteditor.AddMarkerAction.getResource(AddMarkerAction.java:336)
at org.eclipse.ui.texteditor.AddMarkerAction.update(AddMarkerAction.java:162)
at org.eclipse.ui.texteditor.TextEditorAction.<init>(TextEditorAction.java:49)
at org.eclipse.ui.texteditor.AddMarkerAction.<init>(AddMarkerAction.java:96)
at org.eclipse.ui.texteditor.AbstractDecoratedTextEditor.createActions(AbstractDecoratedTextEditor.java:1153)
at org.eclipse.ui.texteditor.AbstractTextEditor.createPartControl(AbstractTextEditor.java:3576)
at org.eclipse.ui.texteditor.StatusTextEditor.createPartControl(StatusTextEditor.java:54)
at org.eclipse.ui.texteditor.AbstractDecoratedTextEditor.createPartControl(AbstractDecoratedTextEditor.java:447)
at org.eclipse.ui.part.MultiPageEditorPart.addPage(MultiPageEditorPart.java:243)
at org.eclipse.ui.forms.editor.FormEditor.addPage(FormEditor.java:325)
....
Your MyEditor
does not have an editor input set.
In your code:
MyEditor myEditor = new MyEditor();
addPage(myEditor, myEditor.getEditorInput());
myEditor.getEditorInput()
will be returning null
because you have not set an input to the editor.
You must pass a proper editor input to the addPage
call (often the input of the multi-page editor). This will then set the input in the editor.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.