RCP Editor 常见错误处理方法 (转)

       最近学习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 "";
    }

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值