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.out.println("Welcome! This is a simple text based game.");
System.out.println("What is your name?");
name =;
System.out.println("Hello, " + name + "! " + "How are you today?");
feelings =;
System.out.println("You're feeling " + feelings + "? Okay! Let's get started.");

Post a Reply


Oldest  Newest  Rating
0 H. P. Lovecraft · February 17, 2015
when you are done using a scanner, remember to call the .close() method on your scanner.
  • 1

Java / Android Development


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

Bucky Roberts Administrator