“Eclipse插件创建”教程:类型SampleView的层次结构不一致

huangapple go评论62阅读模式
英文:

"Create an Eclipse plug-in" tutorial: The hierarchy of the type SampleView is inconsistent

问题

我目前正在完成“创建Eclipse插件”教程,但卡在以下阶段:

在此输入图片描述

我最后做的事情是为扩展org.eclipse.ui.views创建了一个“Hello World!”视图的Java类。然而,我遇到了错误:“类型SampleView的层次结构不一致。”

根据我所了解,这个错误通常是由继承类的.jar文件(在本例中是ViewPart)未包含在项目的构建路径上引起的。

然而,目标平台确实包含了org.eclipse.ui.views插件(其中应该包含org.eclipse.ui.views.jar文件):

在此输入图片描述

对此的任何帮助将不胜感激!

更新:以下是...

plugin.xml:

<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>

   <extension
         point="org.eclipse.ui.commands">
      <category
            id="com.example.helloworld.commands.category"
            name="Sample Category">
      </category>
      <command
            categoryId="com.example.helloworld.commands.category"
            name="Display Hello World"
            id="com.example.helloworld.commands.sampleCommand">
      </command>
   </extension>
   <extension
         point="org.eclipse.ui.handlers">
      <handler
            class="com.example.helloworld.handlers.SampleHandler"
            commandId="com.example.helloworld.commands.sampleCommand">
      </handler>
   </extension>
   <extension
         point="org.eclipse.ui.bindings">
      <key
            commandId="com.example.helloworld.commands.sampleCommand"
            schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
            contextId="org.eclipse.ui.contexts.window"
            sequence="M1+6">
      </key>
   </extension>
   <extension
         point="org.eclipse.ui.menus">
      <menuContribution
            locationURI="menu:org.eclipse.ui.main.menu?after=additions">
         <menu
               id="com.example.helloworld.menus.sampleMenu"
               label="Sample Menu"
               mnemonic="M">
            <command
                  commandId="com.example.helloworld.commands.sampleCommand"
                  id="com.example.helloworld.menus.sampleCommand"
                  mnemonic="S">
            </command>
         </menu>
      </menuContribution>
      <menuContribution
            locationURI="toolbar:org.eclipse.ui.main.toolbar?after=additions">
         <toolbar
               id="com.example.helloworld.toolbars.sampleToolbar">
            <command
                  id="com.example.helloworld.toolbars.sampleCommand"
                  commandId="com.example.helloworld.commands.sampleCommand"
                  icon="icons/sample.png"
                  tooltip="Say hello world">
            </command>
         </toolbar>
      </menuContribution>
   </extension>
   <extension
         point="org.eclipse.ui.views">
      <category
            id="com.example.helloworld.view.helloworldcategory"
            name="Hello World!">
      </category>
      <view
            category="com.example.helloworld.view.helloworldcategory"
            class="com.example.helloworld.view.SampleView"
            id="com.example.helloworld.view.helloworldview"
            name="Hello World!"
            restorable="true">
      </view>
   </extension>

</plugin>

MANIFEST.MF:

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Helloworld
Bundle-SymbolicName: com.example.helloworld;singleton:=true
Bundle-Version: 1.0.0.qualifier
Bundle-Vendor: EXAMPLE
Require-Bundle: org.eclipse.ui
Automatic-Module-Name: com.example.helloworld
Bundle-RequiredExecutionEnvironment: JavaSE-17
英文:

I’m currently working through the “Create an Eclipse plug-in” tutorial, but I’m stuck at the following stage:

enter image description here

The last thing I did was create a Java class for the “Hello World!” View for the extension org.eclipse.ui.views. However, I’m getting the error “The hierarchy of the type SampleView is inconsistent.”

From what I’ve read, this error is often caused by the .jar file of the inherited class (in this case, ViewPart) not being on the build path of the project.

However, the target platform does include the org.eclipse.ui.views plugin (in which the org.eclipse.ui.views.jar file should be contained):

enter image description here

Any help with this would be appreciated!

UPDATE: here are the contents of...

plugin.xml:

&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;?eclipse version=&quot;3.4&quot;?&gt;
&lt;plugin&gt;
&lt;extension
point=&quot;org.eclipse.ui.commands&quot;&gt;
&lt;category
id=&quot;com.example.helloworld.commands.category&quot;
name=&quot;Sample Category&quot;&gt;
&lt;/category&gt;
&lt;command
categoryId=&quot;com.example.helloworld.commands.category&quot;
name=&quot;Display Hello World&quot;
id=&quot;com.example.helloworld.commands.sampleCommand&quot;&gt;
&lt;/command&gt;
&lt;/extension&gt;
&lt;extension
point=&quot;org.eclipse.ui.handlers&quot;&gt;
&lt;handler
class=&quot;com.example.helloworld.handlers.SampleHandler&quot;
commandId=&quot;com.example.helloworld.commands.sampleCommand&quot;&gt;
&lt;/handler&gt;
&lt;/extension&gt;
&lt;extension
point=&quot;org.eclipse.ui.bindings&quot;&gt;
&lt;key
commandId=&quot;com.example.helloworld.commands.sampleCommand&quot;
schemeId=&quot;org.eclipse.ui.defaultAcceleratorConfiguration&quot;
contextId=&quot;org.eclipse.ui.contexts.window&quot;
sequence=&quot;M1+6&quot;&gt;
&lt;/key&gt;
&lt;/extension&gt;
&lt;extension
point=&quot;org.eclipse.ui.menus&quot;&gt;
&lt;menuContribution
locationURI=&quot;menu:org.eclipse.ui.main.menu?after=additions&quot;&gt;
&lt;menu
id=&quot;com.example.helloworld.menus.sampleMenu&quot;
label=&quot;Sample Menu&quot;
mnemonic=&quot;M&quot;&gt;
&lt;command
commandId=&quot;com.example.helloworld.commands.sampleCommand&quot;
id=&quot;com.example.helloworld.menus.sampleCommand&quot;
mnemonic=&quot;S&quot;&gt;
&lt;/command&gt;
&lt;/menu&gt;
&lt;/menuContribution&gt;
&lt;menuContribution
locationURI=&quot;toolbar:org.eclipse.ui.main.toolbar?after=additions&quot;&gt;
&lt;toolbar
id=&quot;com.example.helloworld.toolbars.sampleToolbar&quot;&gt;
&lt;command
id=&quot;com.example.helloworld.toolbars.sampleCommand&quot;
commandId=&quot;com.example.helloworld.commands.sampleCommand&quot;
icon=&quot;icons/sample.png&quot;
tooltip=&quot;Say hello world&quot;&gt;
&lt;/command&gt;
&lt;/toolbar&gt;
&lt;/menuContribution&gt;
&lt;/extension&gt;
&lt;extension
point=&quot;org.eclipse.ui.views&quot;&gt;
&lt;category
id=&quot;com.example.helloworld.view.helloworldcategory&quot;
name=&quot;Hello World!&quot;&gt;
&lt;/category&gt;
&lt;view
category=&quot;com.example.helloworld.view.helloworldcategory&quot;
class=&quot;com.example.helloworld.view.SampleView&quot;
id=&quot;com.example.helloworld.view.helloworldview&quot;
name=&quot;Hello World!&quot;
restorable=&quot;true&quot;&gt;
&lt;/view&gt;
&lt;/extension&gt;
&lt;/plugin&gt;

MANIFEST.MF:

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Helloworld
Bundle-SymbolicName: com.example.helloworld;singleton:=true
Bundle-Version: 1.0.0.qualifier
Bundle-Vendor: EXAMPLE
Require-Bundle: org.eclipse.ui
Automatic-Module-Name: com.example.helloworld
Bundle-RequiredExecutionEnvironment: JavaSE-17

答案1

得分: 0

看起来您还需要在 MANIFEST.MF 中要求 org.eclipse.core.runtime 插件。

因此,清单的 Require-Bundle 部分应为:

Require-Bundle: org.eclipse.core.runtime,
 org.eclipse.ui

在这样做之后,您可能仍然会在视图部分看到一个错误,但现在它将是关于未实现 createPartControlsetFocus 方法。快速修复将处理这个问题,添加类似以下内容:

  @Override
  public void createPartControl(Composite parent)
  {
    // TODO Auto-generated method stub
    
  }

  @Override
  public void setFocus()
  {
    // TODO Auto-generated method stub
    
  }
英文:

It looks like you need to also require the org.eclipse.core.runtime plug-in in the MANIFEST.MF

So the Require-Bundle part of the manifest should be:

Require-Bundle: org.eclipse.core.runtime,
org.eclipse.ui

After doing this you may still have an error showing for the view part but now it will be about not implementing the createPartControl and setFocus methods. Quick fix will deal with that adding something like:

  @Override
  public void createPartControl(Composite parent)
  {
    // TODO Auto-generated method stub
    
  }

  @Override
  public void setFocus()
  {
    // TODO Auto-generated method stub
    
  }

huangapple
  • 本文由 发表于 2023年6月22日 02:57:39
  • 转载请务必保留本文链接:https://go.coder-hub.com/76526343.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定