“线程“AWT-EventQueue-0"中的异常java.lang.NullPointerException".我不知道我做错了什么 [英] "Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException". I have no clue what I'm doing wrong

查看:23
本文介绍了“线程“AWT-EventQueue-0"中的异常java.lang.NullPointerException".我不知道我做错了什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为 AP 计算机科学决赛制作一个计算器.我使用 Jigloo 在 Eclipse 中构建了 GUI,我很快尝试了解 Action Listeners,以便您可以点击按钮来显示数字.当我开始输入实际代码进行计算时,问题开始出现.我不断收到以下错误:

I am making a calculator for an AP Computer Science Final. I built the GUI in Eclipse using Jigloo, and I quickly tried to learn about Action Listeners so you can hit the buttons to make numbers appear. The problems started occurring when I started enter the actual code to make calculations. I keep getting the following error:

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at NewJFrame.<init>(NewJFrame.java:82)
at NewJFrame$1.run(NewJFrame.java:73)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$000(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)

我对 Java 还很陌生,以前从未尝试过这样的项目.如果你们能帮我解决这个问题,我很乐意.这是我的实际代码的链接,由于某种原因它不适合代码框:代码链接

I'm pretty new to Java, and I've never attempted a project like this before. I would love if you guys can help me fix this problem. Here is a link to my actual code, it won't fit in the code box for some reason: Link to code

推荐答案

在调用 initGUI() 之前,不会分配按钮变量,它位于构造函数的底部.所以,当你这样做时:

You button variables aren't assigned until you call initGUI(), which is at the bottom of your constructor. So, when you do this:

jButton3.addActionListener(new ListenToOne());

... Java 看到了:

... Java sees this:

null.addActionListener(new ListenToOne());

...这显然是一个问题.

... which is obviously a problem.

这篇关于“线程“AWT-EventQueue-0"中的异常java.lang.NullPointerException".我不知道我做错了什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆