输入类型不匹配java

时间:2016-03-23 00:14:08

标签: 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, 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();

    }

这是给我所有信息的配置文件

 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

0 个答案:

没有答案