Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2339129
  • 博文数量: 321
  • 博客积分: 3440
  • 博客等级: 中校
  • 技术积分: 2992
  • 用 户 组: 普通用户
  • 注册时间: 2007-05-24 09:08
个人简介

我就在这里

文章分类

全部博文(321)

文章存档

2015年(9)

2014年(84)

2013年(101)

2012年(25)

2011年(29)

2010年(21)

2009年(6)

2008年(23)

2007年(23)

分类: Java

2008-05-18 20:35:46

       最近学习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中标签中没有icon项
            point="org.eclipse.ui.editors">
                  class="testrcp.testeditor"
            id="testrcp.testeditor"
            name="New EditorPart">
     
  

解决方法:plugin.xml中加入icon,该项可以为空。
            point="org.eclipse.ui.editors">
                  class="testrcp.testeditor"
            icon=""
            id="testrcp.testeditor"
            name="New EditorPart">
     
  


                                                                                                                                                                                                     
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 "";
    }
阅读(2903) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~