为什么线程 "AWT-EventQueue-0" java.lang.Error 发生异常?
why Exception in thread "AWT-EventQueue-0" java.lang.Error occured?
由于我是 java 的新手,所以我无法弄清楚为什么会出现此错误以及如何解决它。
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package Code;
import javax.swing.JTable;
/**
*
* @author Regan
*/
public class Report extends javax.swing.JFrame {
/**
* Creates new form Report
*/
public Report() {
initComponents();
for(int i=0;i<Auditor.report.size();i++)
System.out.println(Auditor.report.get(i));
String column[]={"Fragment ID","Status"};
String[][] data=new String[Auditor.report.size()+1][2];
data[0][0]="Fragment ID";
data[0][1]="Status";
for(int i=0;i<Auditor.report.size();i++)
for(int j=0;j<Auditor.report.get(i).size();j++)
data[i+1][j]=Auditor.report.get(i).get(j);
JTable jt=new JTable(data,column);
jt.setBounds(30,40,200,300);
jPanel1.add(jt);
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
jPanel1 = new javax.swing.JPanel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
jLabel1.setFont(new java.awt.Font("Lucida Bright", 1, 36)); // NOI18N
jLabel1.setForeground(new java.awt.Color(169, 11, 63));
jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
jLabel1.setText("AUDITING REPORT");
getContentPane().add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 500, 50));
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 470, Short.MAX_VALUE)
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 390, Short.MAX_VALUE)
);
getContentPane().add(jPanel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 90, 470, 390));
pack();
}// </editor-fold>//GEN-END:initComponents
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(Report.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Report.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Report.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Report.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Report().setVisible(true);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JLabel jLabel1;
private javax.swing.JPanel jPanel1;
// End of variables declaration//GEN-END:variables
}
上面的代码导致了错误,但我仍然对它是 IDE 错误还是我的代码错误感到困惑。 Visual Studio 代码和 NetBeans
都会发生此错误
java.lang.Error: Unresolved compilation problem
的可能原因是什么?
- 是否 IDE 是唯一的问题?
回溯:
Exception in thread "AWT-EventQueue-0" java.lang.Error: Unresolved compilation problems:
org.netbeans cannot be resolved to a type
org.netbeans cannot be resolved to a type
org.netbeans cannot be resolved to a type
at Code.Report.initComponents(Report.java:48)
at Code.Report.<init>(Report.java:20)
at Code.Report.run(Report.java:102)
at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:316)
at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:770)
at java.desktop/java.awt.EventQueue.run(EventQueue.java:721)
at java.desktop/java.awt.EventQueue.run(EventQueue.java:715)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:740)
at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
任何帮助都是感恩
- What are the possible causes of a
java.lang.Error: Unresolved compilation error
problem?
这意味着您的源代码某处存在编译错误,并且您已尝试 运行 代码但未修复编译错误。
异常中的错误消息说 Code.Report
class 中有错误。显然,代码试图使用 org.netbeans
包中的某些内容,但编译器不知道该包是什么。我预计根本原因是缺少 编译时间 项目依赖项。
- Whether IDE is the only problem?
不是真的。可能的根本原因是您的项目配置不正确,并且您忽略了之前构建项目时 IDE 指示给您的编译错误。
- 前者可以出现在不同的 IDE 中。除非您正确配置项目依赖项,否则 IDE 无法为编译器提供正确的 class 路径。
- 后者是你的错,而不是 IDE 的错。你不应该忽略编译错误。
你的问题中没有足够的上下文来说明实际错误在哪里。但是您应该能够通过清理和构建包并查看它报告的编译错误来找到它。
由于我是 java 的新手,所以我无法弄清楚为什么会出现此错误以及如何解决它。
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package Code;
import javax.swing.JTable;
/**
*
* @author Regan
*/
public class Report extends javax.swing.JFrame {
/**
* Creates new form Report
*/
public Report() {
initComponents();
for(int i=0;i<Auditor.report.size();i++)
System.out.println(Auditor.report.get(i));
String column[]={"Fragment ID","Status"};
String[][] data=new String[Auditor.report.size()+1][2];
data[0][0]="Fragment ID";
data[0][1]="Status";
for(int i=0;i<Auditor.report.size();i++)
for(int j=0;j<Auditor.report.get(i).size();j++)
data[i+1][j]=Auditor.report.get(i).get(j);
JTable jt=new JTable(data,column);
jt.setBounds(30,40,200,300);
jPanel1.add(jt);
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
jPanel1 = new javax.swing.JPanel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
jLabel1.setFont(new java.awt.Font("Lucida Bright", 1, 36)); // NOI18N
jLabel1.setForeground(new java.awt.Color(169, 11, 63));
jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
jLabel1.setText("AUDITING REPORT");
getContentPane().add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 500, 50));
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 470, Short.MAX_VALUE)
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 390, Short.MAX_VALUE)
);
getContentPane().add(jPanel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 90, 470, 390));
pack();
}// </editor-fold>//GEN-END:initComponents
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(Report.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Report.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Report.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Report.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Report().setVisible(true);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JLabel jLabel1;
private javax.swing.JPanel jPanel1;
// End of variables declaration//GEN-END:variables
}
上面的代码导致了错误,但我仍然对它是 IDE 错误还是我的代码错误感到困惑。 Visual Studio 代码和 NetBeans
都会发生此错误java.lang.Error: Unresolved compilation problem
的可能原因是什么?- 是否 IDE 是唯一的问题?
回溯:
Exception in thread "AWT-EventQueue-0" java.lang.Error: Unresolved compilation problems:
org.netbeans cannot be resolved to a type
org.netbeans cannot be resolved to a type
org.netbeans cannot be resolved to a type
at Code.Report.initComponents(Report.java:48)
at Code.Report.<init>(Report.java:20)
at Code.Report.run(Report.java:102)
at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:316)
at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:770)
at java.desktop/java.awt.EventQueue.run(EventQueue.java:721)
at java.desktop/java.awt.EventQueue.run(EventQueue.java:715)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:740)
at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
任何帮助都是感恩
- What are the possible causes of a
java.lang.Error: Unresolved compilation error
problem?
这意味着您的源代码某处存在编译错误,并且您已尝试 运行 代码但未修复编译错误。
异常中的错误消息说 Code.Report
class 中有错误。显然,代码试图使用 org.netbeans
包中的某些内容,但编译器不知道该包是什么。我预计根本原因是缺少 编译时间 项目依赖项。
- Whether IDE is the only problem?
不是真的。可能的根本原因是您的项目配置不正确,并且您忽略了之前构建项目时 IDE 指示给您的编译错误。
- 前者可以出现在不同的 IDE 中。除非您正确配置项目依赖项,否则 IDE 无法为编译器提供正确的 class 路径。
- 后者是你的错,而不是 IDE 的错。你不应该忽略编译错误。
你的问题中没有足够的上下文来说明实际错误在哪里。但是您应该能够通过清理和构建包并查看它报告的编译错误来找到它。