简体   繁体   中英

SWT FileDialog with java.lang.ClassNotFoundException

In my java program I'm trying to create a FileDialog to save files. But I'm getting this error.

Caused by: java.lang.ClassNotFoundException: org.eclipse.swt.widgets.FileDialog cannot be found by xxx.xxx.maintenance_1.0.0
    at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:423)
    at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:336)
    at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:328)
    at org.eclipse.osgi.internal.loader.ModuleClassLoader.loadClass(ModuleClassLoader.java:160)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    ... 24 more

This is how I create the dialog:

    public DownloadLogFilesDialog(Shell parent, int style) {
        super(parent, style);
        shell = new Shell(getParent(), SWT.APPLICATION_MODAL);
        fileDialog = new FileDialog(shell, style); // error at this line
    }

    @SuppressWarnings("javadoc")
    public Object open() {
        shell.setSize(width, height);
        Rectangle parentBounds = getParent().getBounds();
        shell.setLocation(
            parentBounds.x + (parentBounds.width - width) / 2,
            parentBounds.y + (parentBounds.height - height) / 2);

        fileDialog.setText("Download Log Files"); //$NON-NLS-1$
        fileDialog.setFilterPath(System.getProperty("user.home")); //$NON-NLS-1$
        Object result = fileDialog.open();
        shell.dispose();
        return result;
    }

After searching for a few days I still have no idea about this. Anyone can help?

EDIT:

MANIFEST.MF

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: System
Bundle-SymbolicName: xxx.xxx.maintenance;singleton:=true
Bundle-Version: 1.0.0
Bundle-Activator: com.xxx.xxx.xxx.ui.maintenance.Activator
Bundle-Vendor: ClareControls
Require-Bundle: 
 org.eclipse.core.runtime;bundle-version="3.10.0",
 org.eclipse.rap.ui;resolution:=optional;visibility:=reexport,
 org.eclipse.rap.ui.forms;resolution:=optional;visibility:=reexport,
 xxx.xxx.common,
 xxx.xxx.db
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Bundle-ActivationPolicy: lazy
Import-Package: 
 com.xxx.xxx.xxx.db.entities;version="1.0.0",
 com.xxx.xxx.xxx.ui.common,
 com.xxx.xxx.xxx.ui.common.editors,
 com.xxx.xxx.xxx.ui.common.events,
 com.xxx.xxx.xxx.ui.components,
 com.xxx.xxx.xxx.ui.db,
 com.xxx.xxx.xxx.ui.projects,
 com.xxx.xxx.xxx.ui.projects.editors,
 com.xxx.xxx.xxx.ui.system.dialogs,
 com.xxx.xxx.xxx.ui.system.views,
 com.xxx.xxx.xxx.util,
 javax.persistence;version="[2.0.1,3.0.0)",
 org.apache.commons.io;version="2.0.0",
 org.json
X-Export-Package: com.xxx.xxx.xxx.ui.maintenance

xxx is just name of some other bundles but I can't show here.

You need to add org.eclipse.swt to the Require-Bundle list in the MANIFEST.MF for your plugin.

You can do this in the plugin.xml editor on the 'Dependencies' tab in the 'Required Plug-ins' table.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM