Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
java中的输入类型不匹配_Java_Input_Types_Mismatch - Fatal编程技术网

java中的输入类型不匹配

java中的输入类型不匹配,java,input,types,mismatch,Java,Input,Types,Mismatch,我遇到了一个错误,我的配置文件(位于代码底部)传入了一个整数,但java抛出了一个输入类型不匹配。有人能给我指出正确的方向吗 public class World implements Runnable{ String fileName; Tile[][] map; Monster[] monArray; int width,height, damage; int hitPoints; int x_coor, y_coor; Avatar avatar; double radius, tor

我遇到了一个错误,我的配置文件(位于代码底部)传入了一个整数,但java抛出了一个输入类型不匹配。有人能给我指出正确的方向吗

 public class World implements Runnable{

String fileName;
Tile[][] map;
Monster[] monArray;
int width,height, damage;
int hitPoints;
int x_coor, y_coor;
Avatar avatar;
double radius, torch;
World world;

 public World(String inFileName){
this.fileName = inFileName;

//Create all the tiles

try {
    Config config = new Config();
    //create the scanner in order to read the file parameters
    Scanner scanner = new Scanner(new File(fileName));
    //Get the height and width of the map
    this.width = scanner.nextInt();
    this.height  = scanner.nextInt();
    //get player starting location

    int x_coor = scanner.nextInt();
    int y_coor = scanner.nextInt();
    //get the player's starting HP
    this.hitPoints = scanner.nextInt();
    //get the player's starting damage
    damage = scanner.nextInt();
    //get starting torch size
    radius = scanner.nextInt();
    Avatar avatar = new Avatar(x_coor,y_coor, hitPoints, damage, radius);
    this.avatar = avatar;
    //create the map with dimensionts
    Tile[][] map = new Tile[width][height];
    //set global map
    this.map = map;
    //set world
    this.world = world; 
    //testing
    //System.out.println("Width is: " +width);
    //System.out.println("Height is: " + height);
    StdDraw.setCanvasSize(width* config.getSize(), height* config.getSize());
    StdDraw.setXscale(0,width * config.getSize());
    StdDraw.setYscale(0,height * config.getSize());
    //print out the design of the map for testing purposes
    for(int i = height -1 ; i >=0; i--){
        for(int j = 0 ; j < width ; j++){
            map[j][i] = new Tile(scanner.next());
            //System.out.println("Tile number:" + i + "," + j + "Has been created");

        }
        System.out.println();

    }
    //getting the information about the monsters
    while(scanner.hasNextLine()){
        //get the character code
        String code = scanner.next();
        //get the x_coor
        int x = scanner.nextInt();
        //get the y_coor
        int y = scanner.nextInt();
        //get the monsters hitpoints
        int hitPoints = scanner.nextInt();
        //get the monster damage amount
        int damage = scanner.nextInt();
        //get the amount of time it sleeps
        int sleepMs = scanner.nextInt();
        //Print out monster stats
        System.out.println("----------------------------");
        System.out.println("Monster Type: " + code);
        System.out.println("Monster Damage: " + damage);
        Monster monster = new Monster(this,code,x,y,hitPoints,damage,sleepMs);
        Thread thread = new Thread(monster);
        thread.start();

    }

while(scanner.hasNextLine())到while(scanner.hasNext())。试试看,我可能错了。你将半径定义为
double
,然后执行
radius=scanner.nextInt()不应该是
radius=scanner.nextDouble()关于代码质量的旁注:除非您打算创建一个无法维护的意大利面代码怪物(好吧,“将”,已经是)。。。我建议你学习罗伯特·马丁的《干净的代码》。并应用其中建议的技术。否则,你会把大部分时间花在寻找奇怪的虫子上;当您尝试添加新功能或更改某些内容时,您永远不知道会有什么中断。while(scanner.hasNextLine())到while(scanner.hasNext())。试试看,我可能错了。你将半径定义为
double
,然后执行
radius=scanner.nextInt()不应该是
radius=scanner.nextDouble()关于代码质量的旁注:除非您打算创建一个无法维护的意大利面代码怪物(好吧,“将”,已经是)。。。我建议你学习罗伯特·马丁的《干净的代码》。并应用其中建议的技术。否则,你会把大部分时间花在寻找奇怪的虫子上;当你试图添加一个新特性或改变某些东西时,你永远不知道什么会中断。
 30 20
 11 2 20 3 100.0
 L L L L L G G G L L L L L L L L L L L L L L L L L L L L L L
 L F L G L S G G G G L L L L L L L L L L L L G G L L L L L L
 L F F G S L S G G G L L L L L M M M L L L G G G F L F F M L
 L F F G G S G G G L L L L L F F F G L L L G G G G G F F M L
 L L L F G G G G G G G L L G G G G G L L L L L G G G F F F L
 L L L G G G G G F G G G G G G L L L L L L L F G L L G F L L
 L L L L G G F F G G G G G S L S L L L L G G F G G G G L L L
 L L L L L G G G G G G L G S L L S L L L G F F G G G G L L L
 L L L G G G L G G G G G G S L G S L L L G F F G L L B L L L
 L L L G L G L G G G L M G G G G L G G G G G G L L L B L L L
 L L M G L L L G G G L L M M G G F F G G G G G L L L G G L L
 L M M L L L L G G G L L L L G G F G G G G G L L G G G G L L
 M M M L L G G G G G G L L L G G G G G M M M L G G G G G L L
 M M S S S L B L L G G L G G G G G G G L L L L G G F F F L L
 L M S B S L B L L L L L G G G G G G G G L M M M G F F L L L
 L L S B B B B L L G G G G G G L L G G G G G G G G F F L L L
 L L S B S L L L F G G L G G L L L G G L G G G G G G L L L L
 L L S S S L L L F F G G G L L L L L L L L G G G G G L L L L
 L L L L L L L L L L L L L L L L L L L L L L L L L L L L L L
 L L L L L L L L L L L L L L L L L L L L L L L L L L L L L L

 SK  3   3   10  3 1000
 OR  6   19  8   2 750
 BA  20  10  4   1 500
 SL  25  16  6   2 1250