Cannot invoke "java.io.Reader.close()" because "reader" is null
时间: 2023-11-09 14:10:15 浏览: 466
C#Control.Invoke方法和跨线程访问控件共
This error message indicates that you are trying to call the `close()` method on a `Reader` object that has not been initialized. In other words, the `reader` variable is null, meaning it does not refer to an actual `Reader` object.
To fix this error, you need to ensure that the `reader` variable is properly initialized before calling any methods on it. You can do this by creating a new `Reader` object and assigning it to the `reader` variable, like this:
```
Reader reader = new FileReader("myfile.txt");
// Use the reader object here
reader.close(); // Make sure to close the reader when you're done with it
```
Alternatively, you can use a try-with-resources statement to automatically close the `Reader` object when you're done with it, like this:
```
try (Reader reader = new FileReader("myfile.txt")) {
// Use the reader object here
}
```
阅读全文