java - 不能将新实例与自定义 JFileChooser 一起使用:没有构造函数?
问题描述
这不是我的程序,但还没有人遇到这个问题,我是第一个,所以最初的开发人员已经尝试帮助我,但无法提供帮助,因为该程序对其他人都很好。
我需要点击一个按钮,这个按钮应该显示一个弹出窗口来选择一个文件(JFileChooser),但是在每个人的电脑上它都可以正常工作,但在我的身上却没有,注意到发生了,没有弹出窗口,只是调试器上的错误。
该程序有一个调试器,即创建错误日志的代码:
return (T)clazz.getConstructor(new Class[0]).newInstance(new Object[0]);
} catch (ReflectiveOperationException e) {
e.printStackTrace();
throw new RuntimeException("No default constructor found for " + clazz.getName());
}
}
/\ 这就是创建日志的原因。
这是调试日志中描述的问题:/
Exception in thread "AWT-EventQueue-0" java.lang.RuntimeException: `
No default constructor found for com.github.manolo8.darkbot.gui.tree.components.JFileOpener
我已经安装了正确的 sdk 和运行时,每个人都在使用,他们没有问题。
这是文件内的代码:“JFileOpener”
import javax.swing.JComponent;
import javax.swing.JDialog;
import javax.swing.JFileChooser;
public class JFileOpener extends JLabel implements OptionEditor {
private final JFileChooser fc = new JFileChooser(new File("."))
{
protected JDialog createDialog(Component parent) throws HeadlessException {
JDialog dialog = super.createDialog(parent);
dialog.setAlwaysOnTop(true);
return dialog;
}
};
public JComponent getComponent() { return this; }
public void edit(ConfigField field) {
setText(Strings.fileName((String)field.get()));
SwingUtilities.invokeLater(() -> {
if (this.fc.showOpenDialog(null) != 0)
return; field.set(this.fc.getSelectedFile().getAbsolutePath());
setText(Strings.fileName((String)field.get()));
});
}
}
解决方案
您是否尝试添加您的JFileOpener
类的默认构造函数?只是为了看看会发生什么?
public class JFileOpener extends JLabel implements OptionEditor {
public JFileOpener() { //Here
super();
}
private final JFileChooser fc = new JFileChooser(new File(".")) {
@Override
protected JDialog createDialog(Component parent) throws HeadlessException {
JDialog dialog = super.createDialog(parent);
dialog.setAlwaysOnTop(true);
return dialog;
}
};
public JComponent getComponent() {
return this;
}
public void edit(ConfigField field) {
setText(Strings.fileName((String) field.get()));
SwingUtilities.invokeLater(() -> {
if (this.fc.showOpenDialog(null) != 0)
return;
field.set(this.fc.getSelectedFile().getAbsolutePath());
setText(Strings.fileName((String) field.get()));
});
}
}
推荐阅读
- c - fseek/ftell 的 C 问题:似乎返回到 txt 文件中的错误位置
- c# - TcpClient.NoDelay 会影响已经写入的数据吗?
- oracle - 无法在 Oracle 列中搜索拼写错误的单词
- python-3.x - 努力理解使用散列函数的粗编码代码
- apexcharts - 在哪里可以找到默认工具提示的 Apexcharts html?
- sql - 非常大的表的最佳 sql(或其他)数据库设计,数千行数千列
- image - 如何在 Flutter 中测试图像小部件的源路径
- php - 如何在codeigniter的列表中插入一个对象
- .htaccess - 410生成的带参数的url
- c# - 无法使用 SlickGrid 示例来渲染网格