Search code examples
eclipseeclipse-plugin

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


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:

<?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

Solution

  • 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
        
      }