0

I am creating RCP application and in that I have to browse file and selected file path is displayed in text box. One button is there to open that selected file. I want to open it in eclipse default editor and I have user listener on button click to open editor. I used below code for opening editor :

   IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
   File file = new File("file path from text box");
   try {
        IFileStore fileStore= EFS.getLocalFileSystem().fromLocalFile(file);
        page.openEditor(new FileStoreEditorInput(fileStore), EditorsUI.DEFAULT_TEXT_EDITOR_ID);                 
    } catch (CoreException ce) {
        ce.printStackTrace();
    }

But when when I select file and click on open file button then new editor opens but file contents are not shown with following error :

Could not open the editor: The editor class could not be instantiated. This usually indicates a missing no-arg constructor or that the editor's class name was mistyped in plugin.xml.

In Details section it is giving error(I have copied part of stack trace) :

java.lang.NoClassDefFoundError: org/eclipse/core/resources/IWorkspace
    at java.lang.Class.getDeclaredConstructors0(Native Method)
    at java.lang.Class.privateGetDeclaredConstructors(Class.java:2493)
    at java.lang.Class.getConstructor0(Class.java:2803)
    at java.lang.Class.newInstance(Class.java:345)
    at org.eclipse.core.internal.registry.osgi.RegistryStrategyOSGI.createExecutableExtension(RegistryStrategyOSGI.java:184)

Please help me with this issue to open file(on button click) in Eclipse default editor.

Many Thanks in advance!!

Prakash
  • 19
  • 8
  • So it can't find `IWorkspace` - do you have the `org.eclipse.core.resources` plug-in in your RCP? – greg-449 Aug 10 '21 at 07:48
  • Yes, I have already added `org.eclipse.core.resources` plugin. – Prakash Aug 10 '21 at 08:01
  • Add to where? All plug-ins need to be listed in the .product file (or a feature included in the product) – greg-449 Aug 10 '21 at 08:59
  • I have added in plugin dependencies, I tried to add in .product file but I found `org.eclipse.core.resources.source` and I added it but no success – Prakash Aug 10 '21 at 10:13
  • Just plugin dependencies is not enough. `org.eclipse.core.resources.source` is the source code - not something you need, it must be `org.eclipse.core.resources`. You must list every plugin that is needed in the product file. – greg-449 Aug 10 '21 at 10:15
  • I have added `org.eclipse.core.resources` and other required plugins as well but still having same issue! – Prakash Aug 10 '21 at 14:54
  • Are you building the RCP (which uses the product file) or are you running from within Eclipse for testing (run as Eclipse Application)- in which case it is the Run Configuration you need to update. – greg-449 Aug 10 '21 at 15:56
  • I have tried with both way by building RCP and running from within eclipse. – Prakash Aug 10 '21 at 16:44
  • I tested this code here and it runs without problems, so it has to be the configuration. The Run Configuration has a "Validate Plug-ins" button they may tell you something. – greg-449 Aug 10 '21 at 16:59
  • Validation is saying 'No problems were detected'.. – Prakash Aug 10 '21 at 17:04

1 Answers1

0

Please try adding default constructor for editor if its a multipage editor

siddu
  • 31
  • 3