首页 \ 问答 \ 在init之外的java中创建一个Object(Creating an Object in java outside of the init)

在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
更新时间:2023-07-16 07:07

最满意答案

由于安全原因,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 ...
  • 截至目前,我们可以使用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.
  • 在服务器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.
  • 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属性现在是“过时的” ...

相关文章

更多

最新问答

更多
  • 如何使用自由职业者帐户登录我的php网站?(How can I login into my php website using freelancer account? [closed])
  • 如何打破按钮上的生命周期循环(How to break do-while loop on button)
  • C#使用EF访问MVC上的部分类的自定义属性(C# access custom attributes of a partial class on MVC with EF)
  • 如何获得facebook app的publish_stream权限?(How to get publish_stream permissions for facebook app?)
  • 如何并排放置两个元件?(How to position two elements side by side?)
  • 在MySQL和/或多列中使用多个表用于Rails应用程序(Using multiple tables in MySQL and/or multiple columns for a Rails application)
  • 如何隐藏谷歌地图上的登录按钮?(How to hide the Sign in button from Google maps?)
  • Mysql左连接旋转90°表(Mysql Left join rotate 90° table)
  • 带有ImageMagick和许多图像的GIF动画(GIF animation with ImageMagick and many images)
  • 电脑高中毕业学习去哪里培训
  • 电脑系统专业就业状况如何啊?
  • IEnumerable linq表达式(IEnumerable linq expressions)
  • 如何在Spring测试中连接依赖关系(How to wire dependencies in Spring tests)
  • Solr可以在没有Lucene的情况下运行吗?(Can Solr run without Lucene?)
  • 如何保证Task在当前线程上同步运行?(How to guarantee that a Task runs synchronously on the current thread?)
  • 在保持每列的类的同时向数据框添加行(Adding row to data frame while maintaining the class of each column)
  • 的?(The ? marks in emacs/haskell and ghc mode)
  • 一个线程可以调用SuspendThread传递自己的线程ID吗?(Can a thread call SuspendThread passing its own thread ID?)
  • 延迟socket.io响应,并“警告 - websocket连接无效”(Delayed socket.io response, and “warn - websocket connection invalid”)
  • 悬停时的图像转换(Image transition on hover)
  • IIS 7.5仅显示homecontroller(IIS 7.5 only shows homecontroller)
  • 没有JavaScript的复选框“关闭”值(Checkbox 'off' value without JavaScript)
  • java分布式框架有哪些
  • Python:填写表单并点击按钮确认[关闭](Python: fill out a form and confirm with a button click [closed])
  • PHP将文件链接到根文件目录(PHP Linking Files to Root File Directory)
  • 我如何删除ListView中的项目?(How I can remove a item in my ListView?)
  • 您是否必须为TFS(云)中的每个BUG创建一个TASK以跟踪时间?(Do you have to create a TASK for every BUG in TFS (Cloud) to track time?)
  • typoscript TMENU ATagParams小写(typoscript TMENU ATagParams lowercase)
  • 武陟会计培训类的学校哪个好点?
  • 从链接中删除文本修饰(Remove text decoration from links)