开发者

Why does my Java code stop responding after an object declaration?

I've been working on a text-based RPG in java, just for fun. After spending many hours of tedious work writing almost a dozen classes for weapons, spells, cmbat systems, shopping systems, etc. I wrote a simple class to start and run the game. All it really does is display a main menu, and create an object which in turn creates every class in the game and starts a new game. The code for the RunGame class is below:

import java.util.Scanner;
import java.util.Random;

public class RunGame {

public static void main(String []args) {    
    Scanner reader = new Scanner(System.in);
    int choice = 0;
    QueratiaMain main = new QueratiaMain();  //code stops responding after creation of this object. why?
//  reader.nextLine();
    System.out.println("Welcome to Queratia, a text-based RPG! Choose an option:\n1. Start New Game\n2. Exit");
    choice = reader.nextInt();      
    if(choice == 1) {       

    }else
        System.exit(99);
}
}

Everything compiles fine, but when I run the program, the code seems to stop progressing at whatever line I create the QueratiaMain object in. Any ideas as to why it would do this? Thanks!

UPDATE: After debugging the code, I got to several lines where the debugger told me that the source was not found, and certain lines were throwing a file not found exception. However, I am working from a normal workspace开发者_StackOverflow中文版 in Eclipse, so how could this be? I tried to manually specify where to find the files, but nothing changed. Any ideas on why this could be happening?


Open the Java debugger. Put a breakpoint on main(). Single step over all the code, and in particular step into the QuertiaMain() constructor. As you step through, eventually you'll come to a line which either hangs or an infinite loop or some such condition that prevents forward progress. It may be obvious why the code loops, or you could post the looping code here for more specific help...


What IDE are you using?

If its Eclipse then right click anywhere on this file and then "Debug As --> Java Application", you will also need to put breakpoints inside your QueratiaMain constructor.


you can find out where your java program is freezing at by kill -3 on linux and ctrl-break on windows.


If you use Java 6 then invoke jvisualvm in the JDK to attach to the running program to see what it is doing.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜