英文:
"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:
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):
Any help with this would be appreciated!
UPDATE: here are the contents of...
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
答案1
得分: 0
看起来您还需要在 MANIFEST.MF 中要求 org.eclipse.core.runtime
插件。
因此,清单的 Require-Bundle
部分应为:
Require-Bundle: org.eclipse.core.runtime,
org.eclipse.ui
在这样做之后,您可能仍然会在视图部分看到一个错误,但现在它将是关于未实现 createPartControl
和 setFocus
方法。快速修复将处理这个问题,添加类似以下内容:
@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
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论