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

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

问题描述

我正在为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&quot;显示java.lang.NullPointerException&QUOT ;.我不知道我做错了什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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