- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
有人可以帮我解决这个错误吗?
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at oopw4.FormManager.searchForm(FormManager.java:51)
at oopw4.FormManager.unregisterForm(FormManager.java:40)
FormManager.class
/*
* 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 oopw4;
import java.util.ArrayList;
import javax.swing.JInternalFrame;
public class FormManager {
private JInternalFrame openedForm = null;
private ArrayList<JInternalFrame> frameList = new ArrayList<>();
public boolean isFormOpened(String namaForm) {
boolean isFound = false;
JInternalFrame jif = searchForm(namaForm);
if (jif != null) {
isFound = true;
openedForm = jif;
}
return isFound;
}
public JInternalFrame getOpenedForm() {
return openedForm;
}
public void registerForm(JInternalFrame frame) {
frameList.add(frame);
}
public void unregisterForm(JInternalFrame frame) {
JInternalFrame jif = (JInternalFrame)searchForm(frame.getName());
if (jif != null) {
frameList.remove(frame);
}
}
private JInternalFrame searchForm(String namaForm) {
JInternalFrame frame = null;
int idx = 0;
while (idx < frameList.size()) {
if (frameList.get(idx).getName().equals(namaForm)) {
frame = frameList.get(idx);
break;
} else {
idx++;
}
}
return frame;
}
}
UserCrud.class
private void closeButtonActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
AppLib.formManager.unregisterForm(this);
}
MainFormDemo.class
/*
* 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 oopw4;
import javax.swing.*;
import simbengkel.AppLib;
public class MainFormDemo extends javax.swing.JFrame {
/**
* Creates new form Frame
*/
public MainFormDemo() {
initComponents();
setExtendedState(JFrame.MAXIMIZED_BOTH);
}
/**
* 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">
private void initComponents() {
DesktopPane = new javax.swing.JDesktopPane();
jMenuBar1 = new javax.swing.JMenuBar();
jMenu1 = new javax.swing.JMenu();
menuOpenedForm = new javax.swing.JMenuItem();
openFormTableUser = new javax.swing.JMenuItem();
menuClosedForm = new javax.swing.JMenuItem();
jMenu2 = new javax.swing.JMenu();
menuHelp = new javax.swing.JMenu();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setLocation(new java.awt.Point(0, 0));
getContentPane().setLayout(new java.awt.GridLayout(1, 0));
javax.swing.GroupLayout DesktopPaneLayout = new javax.swing.GroupLayout(DesktopPane);
DesktopPane.setLayout(DesktopPaneLayout);
DesktopPaneLayout.setHorizontalGroup(
DesktopPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 507, Short.MAX_VALUE)
);
DesktopPaneLayout.setVerticalGroup(
DesktopPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 319, Short.MAX_VALUE)
);
getContentPane().add(DesktopPane);
jMenu1.setText("File");
menuOpenedForm.setText("Tic Tac Toe");
menuOpenedForm.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
menuOpenedFormActionPerformed(evt);
}
});
jMenu1.add(menuOpenedForm);
openFormTableUser.setText("Table User");
openFormTableUser.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
openFormTableUserActionPerformed(evt);
}
});
jMenu1.add(openFormTableUser);
menuClosedForm.setText("Logout");
menuClosedForm.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
menuClosedFormActionPerformed(evt);
}
});
jMenu1.add(menuClosedForm);
jMenuBar1.add(jMenu1);
jMenu2.setText("Edit");
menuHelp.setText("Help");
jMenu2.add(menuHelp);
jMenuBar1.add(jMenu2);
setJMenuBar(jMenuBar1);
pack();
setLocationRelativeTo(null);
}// </editor-fold>
private void menuOpenedFormActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
this.dispose();
TicTacToe main = new TicTacToe();
main.show();
}
private void menuClosedFormActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
this.dispose();
LoginUser login = new LoginUser();
login.show();
}
private void openFormTableUserActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if (AppLib.formManager.isFormOpened("UserCrud")) {
JOptionPane.showMessageDialog(this, "Form Already Opened");
JInternalFrame jif = AppLib.formManager.getOpenedForm();
jif.setVisible(true);
} else {
UserCrud tableUser = new UserCrud();
DesktopPane.add(tableUser);
tableUser.setVisible(true);
AppLib.formManager.registerForm(tableUser);
}
}
/**
* @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(MainFormDemo.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(MainFormDemo.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(MainFormDemo.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(MainFormDemo.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new MainFormDemo().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JDesktopPane DesktopPane;
private javax.swing.JMenu jMenu1;
private javax.swing.JMenu jMenu2;
private javax.swing.JMenuBar jMenuBar1;
private javax.swing.JMenuItem menuClosedForm;
private javax.swing.JMenu menuHelp;
private javax.swing.JMenuItem menuOpenedForm;
private javax.swing.JMenuItem openFormTableUser;
// End of variables declaration
}
错误:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at oopw4.FormManager.searchForm(FormManager.java:51)
at oopw4.FormManager.unregisterForm(FormManager.java:40)
at oopw4.UserCrud.closeButtonActionPerformed(UserCrud.java:263)
at oopw4.UserCrud.access$500(UserCrud.java:24)
at oopw4.UserCrud$6.actionPerformed(UserCrud.java:187)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2348)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
at java.awt.Component.processMouseEvent(Component.java:6533)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3324)
at java.awt.Component.processEvent(Component.java:6298)
at java.awt.Container.processEvent(Container.java:2236)
at java.awt.Component.dispatchEventImpl(Component.java:4889)
at java.awt.Container.dispatchEventImpl(Container.java:2294)
at java.awt.Component.dispatchEvent(Component.java:4711)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4888)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4525)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4466)
at java.awt.Container.dispatchEventImpl(Container.java:2280)
at java.awt.Window.dispatchEventImpl(Window.java:2746)
at java.awt.Component.dispatchEvent(Component.java:4711)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)
at java.awt.EventQueue.access$500(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:709)
at java.awt.EventQueue$3.run(EventQueue.java:703)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
at java.awt.EventQueue$4.run(EventQueue.java:731)
at java.awt.EventQueue$4.run(EventQueue.java:729)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
有人可以帮助我吗?
最佳答案
请记住 Swing UI 在其自己的线程上运行。而且 Swing 中的组件并非设计为线程安全的。那么,欢迎来到 Swing。您可能会发现您的搜索功能在此处发生故障 frameList.get(idx).getName().equals(namaForm)
...因为框架尚未创建。阅读“InvokeLater”并使用它来响应 UX 事件。这可以确保在您尝试对组件执行任何操作之前,执行窗口管理的 Swing 线程全部被捕获。
关于java - 线程中出现异常 "AWT-EventQueue-0"java.lang.NullPointerException JInternalFrame 关闭方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59181661/
在 Tomcat 6/Ubuntu 12.04 上启动 Grails 2.1.0 应用程序时出现以下错误。 Error 500 - Internal Server Error. groovy.lang
在运行 Storm 拓扑时,我收到此错误。拓扑完美运行 5 分钟,没有任何错误,然后失败。我正在使用 Config.TOPOLOGY_TICK_TUPLE_FREQ_SECS as 300 sec i
我有一个 jsp 代码在其中一台机器上运行良好。但是当我复制到另一台机器时,我得到了这个 no such method found 异常。我是 Spring 的新手。有人可以解释我错过了什么吗? 以下
已关闭。此问题需要 debugging details 。目前不接受答案。 编辑问题以包含 desired behavior, a specific problem or error, and the
我的代码在下面给出了一个错误; Exception in thread "main" java.lang.NoSuchMethodError: com/myApp/Client.cypherCBC(L
我正在尝试一个 Restful web 服务示例,所以当我要访问 url 时,我遇到了异常 java.lang.NoSuchMethodError: jersey.repackaged.com.goo
我正在将一个 Spring web 项目转换为一个 Maven 项目,但我收到了这个错误: java.lang.NoSuchMethodError: org.jboss.logging.Logger.
在我的项目中,我有一个像这样的枚举: public enum MyEnum { FIRST(1), SECOND(2); private int value; private MyEnum(int v
我创建了这个简单的示例,用于读取 Linux 正常运行时间: public String getMachineUptime() throws IOException { String[] di
我正在使用 Eclipse,并且正在使用 Java。我的目标是使用 bogoSort 方法对 vector 进行排序在一个 vector (vectorExample)中适应我的 vector 类型,
我正在运行以下查询。它显示一条错误消息。如何解决这个错误? ListrouteList=null; List companyList = session.createS
我有以下模型类: @Entity @Table(name="user_content") @org.hibernate.annotations.NamedQueries({ @org.
我有那个错误。这是我的代码: GmailSettingsService service = new GmailSettingsService(APPLICATION_NAME, DOMAIN_NAME
实际上我在执行我的java程序时遇到了下面提到的错误 Exception in thread "pool-1-thread-1" java.lang.ClassCastException: jav
java.lang.ClassCastException: java.lang.Float cannot be cast to java.lang.String 我在以下代码中遇到此异常: Strin
我正在尝试从 linkedhashset 中检索随机元素。下面是我的代码,但它每次都给我异常。 private static void generateRandomUserId(Set userIds
我已经完成了 Android 中的代码: List spinnerArray = new ArrayList(); for (int i = 0; i item = (LinkedTreeMap)
这个问题已经有答案了: Explanation of ClassCastException in Java (12 个回答) 已关闭 6 年前。 我已经编写了 java 到 Json 的代码,同时从页
这个问题在这里已经有了答案: ClassCastException java.lang.Long cannot be cast to clojure.lang.IFn (4 个答案) 关闭 6 年前
我在运行时遇到问题来编译这段代码,这给我一个错误,java.lang.Integer 无法转换为 Java.lang.Double。如果有人帮助我更正此代码,我将非常高兴 double x; pu
我是一名优秀的程序员,十分优秀!