2012-04-05 230 views
-1

我有一個擴展TextEditor的類來創建編輯器視圖。我已經完成了所有必需的條目,如plugin.xml。現在,我收到以下錯誤打開編輯器...打開Eclipse插件編輯器

org.eclipse.core.runtime.AssertionFailedException:null參數:編輯輸入必須有一個非空的名字

我我正在使用下面的代碼打開編輯器。

IWorkbenchPage page = 
    PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); 
page.openEditor(input, xyz.ID); 
+0

你應該檢查你的輸入對象,因爲錯誤消息提示。你正在使用'FileEditorInput'或其他東西?你的輸入是否包含任何實際的數據? – 2012-04-05 08:28:59

回答

-1

以下代碼是該問題的正確解決方案。

if (fileToOpen.exists() && fileToOpen.isFile()) { 
    Stirng path = // file path that to be input.; 
    IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); 
    URI fromString = org.eclipse.core.runtime.URIUtil.fromString("file://" + path); 
    try { 
     IEditorPart openEditor = IDE.openEditor(page, fromString, XYZEditor.ID, true); 
     IEditorInput editorInput = openEditor.getEditorInput(); 
     //editorInput. 
    } catch (PartInitException e) { 
     //Put your exception handler here if you wish to 
    } 
}