resource leak 'context' is never closed

+3 wil's wilson · January 15, 2015
hi guys i tried writing the Scanner statement out

import java.util.Scanner;
public class apples {
public static void main(String args[]){
double tuna;
tuna = 5.25;
System.out.println(tuna);
Scanner wils = new Scanner(System.in);    ............warning msg resource leak wils is never closed
System.out.println(wils.nextLine());
}
}

what shoud i do. thank

Post a Reply

Replies

Oldest  Newest  Rating
0 Neil Cannon · January 25, 2015
wils.close();
0 Tim Herreijgers · January 16, 2015
Try this:


import java.util.Scanner;

public class apples {

public static void main(String args[]){

double tuna = 5.25;

System.out.println(tuna);

Scanner wils = new Scanner(System.in);
String x = wils.nextLine();
System.out.println(wils);
}
}




You can close your scanner with wils.close()
0 wil's wilson · January 16, 2015
how do i close it. the above code still not working
0 Troy Jones · January 16, 2015
You aren't storing anything with what you are typing in your scanner, if that makes any sense.
Try this:


import java.util.Scanner;

public class apples {

public static void main(String args[]){

double tuna = 5.25;

System.out.println(tuna);

Scanner wils = new Scanner(System.in);
String wils = Scanner.nextLine();
System.out.println(wils);
}
}
-1 Branislav Lazic · January 16, 2015
Well... close it.
  • 1

Java / Android Development

107,158 followers
About

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

Links
Moderators
Bucky Roberts Administrator