gpt4 book ai didi

java - 尝试设置 jcheckbox 时出现 NullPointerException

转载 作者:行者123 更新时间:2023-12-01 16:09:53 25 4
gpt4 key购买 nike

尝试对其进行设置,以便如果满足特定条件,则将选中两个复选框之一。但是我不断收到 nullpointerexception 错误。

代码是..

        //Set the flat rate or hourly billing check boxes.
if(flatRateint > 0) {
InvoiceUI.jCheckBox1.setSelected(true);
}
else {
InvoiceUI.jCheckBox2.setSelected(true);
}

错误是

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException at my.freelancebillingapp.InvoiceSelectionUI.jButton1MouseClicked(InvoiceSelectionUI.java:224) at my.freelancebillingapp.InvoiceSelectionUI.access$100(InvoiceSelectionUI.java:17) at my.freelancebillingapp.InvoiceSelectionUI$2.mouseClicked(InvoiceSelectionUI.java:86) at java.awt.AWTEventMulticaster.mouseClicked(AWTEventMulticaster.java:253) at java.awt.Component.processMouseEvent(Component.java:6266) at javax.swing.JComponent.processMouseEvent(JComponent.java:3267) at java.awt.Component.processEvent(Component.java:6028) at java.awt.Container.processEvent(Container.java:2041) at java.awt.Component.dispatchEventImpl(Component.java:4630) at java.awt.Container.dispatchEventImpl(Container.java:2099) at java.awt.Component.dispatchEvent(Component.java:4460) at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4574) at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4247) at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168) at java.awt.Container.dispatchEventImpl(Container.java:2085) at java.awt.Window.dispatchEventImpl(Window.java:2475) at java.awt.Component.dispatchEvent(Component.java:4460) at java.awt.EventQueue.dispatchEvent(EventQueue.java:599) at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269) at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161) at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)

最佳答案

假设 InvoiceSelectionUI.java 的第 224 行包含在您的示例中,则以下之一必须为 null:

  • 发票UI
  • InvoiceUI.jCheckBox1
  • InvoiceUI.jCheckBox2
  • flatRateint(如果它是 Integer,但如果它是 int,则不是)

关于java - 尝试设置 jcheckbox 时出现 NullPointerException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1652945/

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