-3

I created a java program that get input from the user by Scanner.

import java.util.Scanner;
Scanner scan = new Scanner(System.in);
int first = scan.nextInt();

(I used more than 1 scanning).

Afterward I tried to create an Android application using my code, but the application got stack because the scanner. How can I import the java scanner into Android studio?

Elad
  • 9
  • 3

1 Answers1

0

java.util.Scanner is in Android. See Android Scanner JavaDoc. Your program should work without conversion.

Maybe you need to add to your import statement(s) to import java.util.*. Just a guess.

It would help if you added the error message to your question.

Maybe the issue is not with Scanner but with System.in. Try replacing System.in with a String constant Ex:"This is my text";

fishjd
  • 1,617
  • 1
  • 18
  • 31
  • Webre should I add the import statement? – Elad Jan 08 '19 at 21:07
  • There is no error message, the application just stop working. – Elad Jan 08 '19 at 21:20
  • Just write { Scanner scan = new Scanner ("this is my text"); }? – Elad Jan 09 '19 at 23:44
  • Correct, Just to see if it will work. Then we will know if System.in is the problem. – fishjd Jan 11 '19 at 01:08
  • I tried to run the program as method, and I got runtime error message when it tried to run the Scanner (the same one, I didn't change it) - Caused by: java.util.NoSuchElementException at java.util.Scanner.throwFor(Scanner.java:874) at java.util.Scanner.next(Scanner.java:1502) at java.util.Scanner.nextInt(Scanner.java:2134) at java.util.Scanner.nextInt(Scanner.java:2093) at – Elad Jan 15 '19 at 21:48