gpt4 book ai didi

Java编译警告

转载 作者:塔克拉玛干 更新时间:2023-11-01 22:14:49 24 4
gpt4 key购买 nike

Netbeans 7.1.1 中(成功)构建 JAR 文件时,我遇到了这个警告:

...
warning: [options] bootstrap class path not set in conjunction with -source 1.6
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
1 warning
...

这是什么意思?此外,Java 运行时是否会影响 JAR(应用程序)的兼容性?

当我在 XPUbuntu 中运行 JAR 时,应用程序看起来很好,但是当我尝试在 Fedora 上运行它时,它当我右键单击 JTable 时,不使用全屏并且没有上下文菜单。我该怎么办?

一些代码片段:

此代码调用 JFrame 并在加载时将其设置为全屏,但这在 Fedora 中不起作用。

this.setVisible(false);
frmMain xForm = new frmMain();

xForm.setLocationRelativeTo(null);
GraphicsEnvironment e = GraphicsEnvironment.getLocalGraphicsEnvironment();

xForm.setMaximizedBounds(e.getMaximumWindowBounds());
xForm.setExtendedState(xForm.getExtendedState()|JFrame.MAXIMIZED_BOTH );
xForm.setVisible(true);

当我右键单击 JTable 以显示上下文菜单时,它在 Windows 中正常工作,但在 fedoraUbuntu 中却不行>.

private void tableItemMouseReleased(java.awt.event.MouseEvent evt) {                                        

if ( SwingUtilities.isRightMouseButton( evt ))
{
int r = tableItem.rowAtPoint(evt.getPoint());
if (r >= 0 && r < tableItem.getRowCount())
{
tableItem.setRowSelectionInterval(r, r);
}
else
{
tableItem.clearSelection();
}

int rowindex = tableItem.getSelectedRow();
if (rowindex < 0)
return;

if (evt.isPopupTrigger() && evt.getComponent() instanceof JTable )
{
pmItem.show(evt.getComponent(), evt.getX(), evt.getY());
}
}
}

更新 1

通过在编译选项中添加 -Xlint:unchecked,我得到了这个警告:

warning: [options] bootstrap class path not set in conjunction with -source 1.6

C:\Documents and Settings\Totet\My Documents\NetBeansProjects\DCWD_DepreciationMonitoringSystem\src\DCWDDMS\frmItemDepreciation.java:432:
warning: [unchecked] unchecked call to addElement(E) as a member of the raw type Vector
newRow.addElement(rs.getObject(i));
where E is a type-variable:
E extends Object declared in class Vector

C:\Documents and Settings\Totet\My Documents\NetBeansProjects\DCWD_DepreciationMonitoringSystem\src\DCWDDMS\frmMain.java:351:
warning: [unchecked] unchecked call to addElement(E) as a member of the raw type Vector
newRow.addElement(rs.getObject(i));
where E is a type-variable:
E extends Object declared in class Vector

C:\Documents and Settings\Totet\My Documents\NetBeansProjects\DCWD_DepreciationMonitoringSystem\src\DCWDDMS\frmNewItem.java:831:
warning: [unchecked] unchecked call to addElement(E) as a member of the raw type DefaultComboBoxModel
model.addElement(resultList.getString(1));
where E is a type-variable:
E extends Object declared in class DefaultComboBoxModel

C:\Documents and Settings\Totet\My Documents\NetBeansProjects\DCWD_DepreciationMonitoringSystem\src\DCWDDMS\frmNewItem.java:833:
warning: [unchecked] unchecked call to setModel(ComboBoxModel<E>) as a member of the raw type JComboBox
cmbAccount.setModel(model);
where E is a type-variable:
E extends Object declared in class JComboBox

5 warnings

最佳答案

源/二进制格式设置

这里是显式设置项目源和目标的显式方法。大多数时候,您不需要摆弄这个,一旦您在 netbeans 中设置了项目特定的 Java 平台。

  1. 右键单击“项目”并选择“属性”
  2. 选择来源
  3. 将源级别设置为 6(源/二进制格式)
  4. 单击“确定”按钮。

不安全操作警告

我一般会忽略“不安全操作警告”。但是如果你想知道为什么显示它,请使用 -Xlint:unchecked 选项重新编译(在上面的第 5 步),它会解释报告为不安全的内容和原因。

Fedora 中的 UI 问题

在 Fedora 上检查您的路径以确保您没有运行默认的 GNU Java 运行时。

进入命令行并输入

java -version看看它返回了什么。它必须返回 Oracle (sun) 的 java 信息​​。否则,您将面临问题,尤其是 Swing/UI 方面的问题。

关于Java编译警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9779763/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com