在init之外的java中创建一个Object(Creating an Object in java outside of the init)
所以对于我正在创建的游戏,我有一些扩展GameDriver的类。
到目前为止,在所有其他课程中,我已经能够扩展GameDriver,然后在GameDriver中,我可以做到:
ArrayList<Card> library = new ArrayList<Card>();
今天我开始使用GameAI课程,并扩展了GameDriver,当我放入时:
GameAI Enemy = new GameAI();
在同一个地方,我把另一行代码(在公共类GameDriver下面)
我明白了:
java.lang.StackOverflowError at java.util.WeakHashMap.expungeStaleEntries(Unknown Source) at java.util.WeakHashMap.getTable(Unknown Source) at java.util.WeakHashMap.get(Unknown Source) at java.awt.Component.checkCoalescing(Unknown Source) at java.awt.Component.<init>(Unknown Source) at java.awt.Container.<init>(Unknown Source) at java.awt.Panel.<init>(Unknown Source) at java.awt.Panel.<init>(Unknown Source) at java.applet.Applet.<init>(Unknown Source) at GameDriver.<init>(GameDriver.java:14) at GameAI.<init>(GameAI.java:8) at GameDriver.<init>(GameDriver.java:40) at GameAI.<init>(GameAI.java:8)
如果我把它放在我的applet的public void init()中,那么它在运行时不会出错,但是后来我无法从其他方法访问它,我在看什么? 所有的打火机通常都无法帮助我的大脑......
这就是GameAI现在的样子:
public class GameAI extends GameDriver { public int life; public int energy; public void drawPhase(){ } public GameAI(){ life = 20; energy = 2; } }
然后GameDriver的一些部分:
public class GameDriver extends Applet implements MouseMotionListener,MouseListener { Graphics g; Image offscreen; Dimension dim; int playerLife = 20; int playerEnergy = 8; int xMouse; int yMouse; int lineThickness = 4; int handSize = 6; int currentHover; boolean slotHover; int currentSelected; boolean slotClicked; int currentHoverBoard; boolean slotHoverBoard; boolean slotClickedBoard; int currentSelectedBoard; boolean canPlace; ArrayList<Card> library = new ArrayList<Card>(); ArrayList<Card> hand = new ArrayList<Card>(); ArrayList<Card> playerBoard = new ArrayList<Card>(); GameAI Enemy; int[] handBoxX = new int[handSize]; int[] handBoxY = new int[handSize]; int[] handBoxW = new int[handSize]; int[] handBoxH = new int[handSize]; int[] playerBoardX = new int[8]; int[] playerBoardY = new int[8]; int[] playerBoardW = new int[8]; int[] playerBoardH = new int[8]; public void init(){ this.setSize(640, 480); dim = this.getSize(); addMouseMotionListener(this); addMouseListener(this); createLibrary(); drawFirstHand(); printHand(); GameAI Enemy = new GameAI(); checkEnemy(); offscreen = createImage(this.getSize().width,this.getSize().height); g = offscreen.getGraphics(); } public void checkEnemy(){ System.out.println(Enemy.energy); } ... Alot more methods and stuff below, but nothing to do with the GameAI enemy
so for the game I'm creating I have a few classes that extend GameDriver.
Up until this point, on all the other classes I've been able to extend GameDriver and then In GameDriver I can do:
ArrayList<Card> library = new ArrayList<Card>();
Today I started on the GameAI class and I extended GameDriver, and when I put:
GameAI Enemy = new GameAI();
In the same spot I put the other line of code (Right below public class GameDriver)
I get:
java.lang.StackOverflowError at java.util.WeakHashMap.expungeStaleEntries(Unknown Source) at java.util.WeakHashMap.getTable(Unknown Source) at java.util.WeakHashMap.get(Unknown Source) at java.awt.Component.checkCoalescing(Unknown Source) at java.awt.Component.<init>(Unknown Source) at java.awt.Container.<init>(Unknown Source) at java.awt.Panel.<init>(Unknown Source) at java.awt.Panel.<init>(Unknown Source) at java.applet.Applet.<init>(Unknown Source) at GameDriver.<init>(GameDriver.java:14) at GameAI.<init>(GameAI.java:8) at GameDriver.<init>(GameDriver.java:40) at GameAI.<init>(GameAI.java:8)
If I put it in the public void init() of my applet, then it doesn't give an error on run, but then I wouldn't be able to access it from my other methods, am I over looking something? All nighters normally don't help my brain...
This is what the GameAI looks like as of right now:
public class GameAI extends GameDriver { public int life; public int energy; public void drawPhase(){ } public GameAI(){ life = 20; energy = 2; } }
And then some bits of the GameDriver:
public class GameDriver extends Applet implements MouseMotionListener,MouseListener { Graphics g; Image offscreen; Dimension dim; int playerLife = 20; int playerEnergy = 8; int xMouse; int yMouse; int lineThickness = 4; int handSize = 6; int currentHover; boolean slotHover; int currentSelected; boolean slotClicked; int currentHoverBoard; boolean slotHoverBoard; boolean slotClickedBoard; int currentSelectedBoard; boolean canPlace; ArrayList<Card> library = new ArrayList<Card>(); ArrayList<Card> hand = new ArrayList<Card>(); ArrayList<Card> playerBoard = new ArrayList<Card>(); GameAI Enemy; int[] handBoxX = new int[handSize]; int[] handBoxY = new int[handSize]; int[] handBoxW = new int[handSize]; int[] handBoxH = new int[handSize]; int[] playerBoardX = new int[8]; int[] playerBoardY = new int[8]; int[] playerBoardW = new int[8]; int[] playerBoardH = new int[8]; public void init(){ this.setSize(640, 480); dim = this.getSize(); addMouseMotionListener(this); addMouseListener(this); createLibrary(); drawFirstHand(); printHand(); GameAI Enemy = new GameAI(); checkEnemy(); offscreen = createImage(this.getSize().width,this.getSize().height); g = offscreen.getGraphics(); } public void checkEnemy(){ System.out.println(Enemy.energy); } ... Alot more methods and stuff below, but nothing to do with the GameAI enemy
原文:https://stackoverflow.com/questions/12027435
最满意答案
由于安全原因,ASP.NET Dev Server不接受其他计算机发出的连接。 我曾经遇到过这种情况,作为解决方案,我找到了这个链接 。
告诉我们使用“Trace Utility” 。 只需查看该链接即可。 对于其他替代解决方案,请检查此SO链接并检查Jon Galloway给出的答案。
The ASP.NET Dev Server will not accept connections issued by other computers because of security reason. I have had faced this kind of situation in the past and as a solution i have found This link.
Which tell us to use “Trace Utility”. Just check out that link. For other alternative solution, please check this SO Link and check the answer given by Jon Galloway.
相关问答
更多-
是的你可以! 而且你不需要IIS 只需使用一个简单的Java TCP隧道。 下载这个Java应用程序,只是将流量传回来。 http://jcbserver.uwaterloo.ca/cs436/software/tgui/tcpTunnelGUI.shtml 在命令提示符下,您将运行这样的java应用程序...我们假设您想要在端口80上进行外部访问,并且您的标准调试环境在端口1088上运行... java -jar tunnel.jar 80 localhost 1088 (也在这里回答: 访问VM外部的 ...
-
尝试将dll放在\ System32 \ Inetsrv目录中。 这是Windows Server上IIS的工作目录。 如果这不行,请尝试将dll放在System32目录中,并将依赖文件放在Inetsrv目录中。 Try putting the dlls in the \System32\Inetsrv directory. This is the working directory for IIS on Windows Server. If this doesn't work try putting th ...
-
HTTPS与Visual Studio的内置ASP.NET开发服务器(HTTPS with Visual Studio's built-in ASP.NET Development Server)[2023-11-04]
截至目前,我们可以使用IIS Express在SSL中开发和测试。 以下是一篇完整的文章,介绍如何使用IIS Express和Visual Studion 2010开发SSL中的网站 下一个 然后你会得到这个 在开发时使用SSL更容易使用IISExpress 介绍IIS Express As of now we can use IIS Express to develop and test in SSL. Here is a complete article explaning how to use IIS ... -
由于您的所有用户似乎都已通过身份验证,因此我建议您考虑使用管理会话状态和超时的其他方式。 部分问题在于,如果用户只是关闭浏览器而不注销,或者停止使用应用程序,则必须等到会话超时后才能将其关闭并释放UniObjects以解决授权问题。 我的建议如下: 如果您没有使用MasterPages,请向您的MasterPage模板或网站中的每个页面添加隐形IFRAME。 该MasterPage将加载包含META Refresh的KeepAlive.aspx页面,每5分钟重新加载页面。 您可以将会话超时减少到10分钟(甚 ...
-
不,cassini只能从运行它的机器上访问。 No, cassini can only be accessed from the machine it is running on.
-
从其他服务器反映(或动态加载)Asp.NET网站(Reflecting (or loading dynamically) Asp.NET website from the other server)[2023-06-29]
在服务器B上运行Asp.NET站点,并为服务器A构建简单代理并对流量进行隧道传输。 (怎么样?) 只需少量点击或命令行指令, 任何 HTTP代理都可以执行此操作。 我不会去任何其他道路。 Run Asp.NET site on server B and build simple proxy to server A and tunnel the traffic. (how?) Any HTTP proxy can do this, with a mere handful of clicks or comman ... -
你可以从Request中获得它: Request.Url.Port 这不是开发Web服务器的严格端口,这是当前使用的Web服务器的端口。 You can get it from Request: Request.Url.Port And this is not strictly port of Development web server, this is a port of currently used web server.
-
ASP.NET Web开发服务器(ASP.NET Web Development Server)[2023-01-28]
Web服务器是名为WebDev.WebServer.EXE的可执行文件,位于\ WINDOWS \ Microsoft.NET \ Framework \ v2.0.50727中。 在调试网站时,Visual Studio使用以下参数启动应用程序的实例。 WebDev.WebServer.exe \ port \ path [\ vpath] 此ASP.NET开发服务器仅使用调试文件夹中的已编译Web应用程序(以/ path形式提供)来为网站提供服务。 你可以在这里阅读更多。 The web server ... -
由于安全原因,ASP.NET Dev Server不接受其他计算机发出的连接。 我曾经遇到过这种情况,作为解决方案,我找到了这个链接 。 告诉我们使用“Trace Utility” 。 只需查看该链接即可。 对于其他替代解决方案,请检查此SO链接并检查Jon Galloway给出的答案。 The ASP.NET Dev Server will not accept connections issued by other computers because of security reason. I have ...
-
好。 我找到了答案......虽然拍摄了一天中更好的部分。 原来我们的一个渠道接收提供商抛出了403错误,该错误过滤了IP值。 渠道接收器提供商编写了一些重要的假设。 首先,它正在寻找呼叫机器的地址并将其与ip白名单进行比较。 作者盲目地收集了列表中的第一个第一个条目: Dns.GetHostEntry(machineName).AddressList[0].Address 在我的新机器上,我启用了IPv6,因此第一个条目实际上是IPv6条目。 在引用MSDN之后,我发现Address属性现在是“过时的” ...