现在的位置: 首页 > 综合 > 正文

RCP Editor 常见错误处理方法

2013年06月30日 ⁄ 综合 ⁄ 共 4168字 ⁄ 字号 评论关闭

最近学习RCP遇到不少问题,解决后觉得应该写点东西与同道朋友们分享一下。笔者也是刚刚接触RCP如文章中有错误欢迎执政。本文只涉及报错信息及解决方法,希望高手能够解释深层次的原因。

"org.eclipse.ui.PartInitException: Unable to open editor, unknown editor ID: package.class"、"org.eclipse.ui.PartInitException: Editor initialization failed: package.class.  Site is incorrect."及"org.eclipse.core.runtime.AssertionFailedException: null argument:A part's title tool tip must be non-null"处理方法

1."org.eclipse.ui.PartInitException: Unable to open editor, unknown editor ID: package.class"处理方法
报错原因:plugin.xml中<extension>标签中没有icon项
   <extension
         point="org.eclipse.ui.editors">
      <editor
            class="testrcp.testeditor"
            id="testrcp.testeditor"
            name="New EditorPart">
      </editor>
   </extension>
解决方法:plugin.xml中<extension>加入icon,该项可以为空。
   <extension
         point="org.eclipse.ui.editors">
      <editor
            class="testrcp.testeditor"
            icon=""
            id="testrcp.testeditor"
            name="New EditorPart">
      </editor>
   </extension>

                                                                                                                                                                                                     
2."org.eclipse.ui.PartInitException: Editor initialization failed: package.class.  Site is incorrect."处理方法
报错原因:EditorPart类的init()未实现
package testrcp;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorSite;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.part.EditorPart;

public class testeditor extends EditorPart {

    public static final String ID = "testrcp.testeditor"; //$NON-NLS-1$

    /**
     * Create contents of the editor part
     * @param parent
     */
    //@Override
   
    public void createPartControl(Composite parent) {
        Composite container = new Composite(parent, SWT.NONE);
        //
    }

    @Override
    public void setFocus() {
        // Set the focus
    }

    @Override
    public void doSave(IProgressMonitor monitor) {
        // Do the Save operation
    }

    @Override
    public void doSaveAs() {
        // Do the Save As operation
    }

    @Override
    public void init(IEditorSite site, IEditorInput input)
            throws PartInitException {
           
    }

    @Override
    public boolean isDirty() {
        return false;
    }

    @Override
    public boolean isSaveAsAllowed() {
        return false;
    }

}
解决方法:实现init()方法如下  
    public void init(IEditorSite site, IEditorInput input)
            throws PartInitException {
       
        System.out.println(input.toString());
        this.setInput(input);
        this.setSite(site);
   
    }
   
                                                                                                                                                                                                     
3."org.eclipse.core.runtime.AssertionFailedException: null argument:A part's title tool tip must be non-null"处理方法
报错原因:EditorInput类的getToolTipText()返回值为null  
package testrcp;

import org.eclipse.core.runtime.IPath;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.ui.IPathEditorInput;
import org.eclipse.ui.IPersistableElement;

public class testEditorInput implements IPathEditorInput {

    public testEditorInput() {
        // TODO Auto-generated constructor stub
        super();
       
    }

    @Override
    public IPath getPath() {
        // TODO Auto-generated method stub
        return null;
    }

   
    @Override
    public boolean exists() {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    public ImageDescriptor getImageDescriptor() {
        // TODO Auto-generated method stub
        return null;//WorkbenchImages.getImageDescriptor("");
    }

    @Override
    public String getName() {
        // TODO Auto-generated method stub
        return "testEditorInput";
    }

    @Override
    public IPersistableElement getPersistable() {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public String getToolTipText() {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public Object getAdapter(Class adapter) {
        // TODO Auto-generated method stub
        return null;
    }

}
解决方法:重写getToolTipText()方法return值可以为""或任意字符类型。
    public String getToolTipText() {
        // TODO Auto-generated method stub
        return "";
    }

 

本文出处:http://blog.csdn.net/jiashiwen/archive/2008/04/22/2315077.aspx

抱歉!评论已关闭.