Resource Leak

+2 Lucas Skarpness · February 17, 2015
I have come across the minor problem in Java. I was making a simple text game for fun, and my scanner variable (if you call it that) says "Resource leak: "in" is never closed"

The program runs fine, it's just something that bothers me. I know its there and though theres a slight error it still runs. Any explanations?


import java.util.Scanner;

public class TGMain {

public static void main(String[] args) {
String name;
String feelings;
Scanner in = new Scanner(System.in);
System.out.println("Welcome! This is a simple text based game.");
System.out.println("What is your name?");
name = in.next();
System.out.println("Hello, " + name + "! " + "How are you today?");
feelings = in.next();
System.out.println("You're feeling " + feelings + "? Okay! Let's get started.");
}
}

Post a Reply

Replies

Oldest  Newest  Rating
0 Mathias Frits Rørvik · February 17, 2015
when you are done using a scanner, remember to call the .close() method on your scanner.
  • 1

Java / Android Development

107,142 followers
About

Very popular language used to create desktop applications, website applets, and Android apps.

Links
Moderators
Bucky Roberts Administrator