No suitable method found for write

后端 未结 1 389
终归单人心
终归单人心 2021-01-27 17:34

Im attempting to write a previously created array to file. This is the error im getting and I don\'t know how to fix it.

Zoo.java:341: error: no suitable method          


        
1条回答
  •  抹茶落季
    2021-01-27 18:33

    Animals is a class that Java doesn't know how to convert it to String, int, or char.

    I assume you want to write Animals instance data to file Output.txt.

    In that case, you should define toString() method in Animals class, so the print function can convert the instance to string and write that to the file.

    class Animals {
        String name;
    
        @Override
        public String toString() {
            return "Animal name : " + name;
        }
     }
    

    See:
    http://www.javatpoint.com/understanding-toString()-method

    0 讨论(0)
提交回复
热议问题