Skip to content
Advertisement

When running the Scanner class to insert a number in android studio, it does not work

In android studio, when I run a simple code to get an integer number, it gives me an error regarding the Scanner class.

 import java.util.Scanner;
 public class MyClass {
 public static void main(String[] args){
 Scanner yadigar = new Scanner(System.in);
 int a = yadigar.nextInt();
 System.out.println("a");
 } 
}

I just expected it to print a number but unlike eclipse and other IDEs it gave an error. I actually tried to modify gradle, but it did not work(maybe I did something wrong, I am not sure honestly). Execution failed for task ‘:yad:MyClass.main()’.

Process ‘command ‘C:/Program Files/Android/Android Studio/jre/bin/java.exe” finished with non-zero exit value 1

  • Try: Run with –stacktrace option to get the stack trace. Run with –info or –debug option to get more log output. Run with –scan to get full insights.

Advertisement

Answer

In Android studio you can create android apps . and if you want to run a standalone projects you can use this hacky way . The main function is not registered the default program to run in Android Studio.

I would suggest you to use Intellij idea community edition which has all the features you would have in android studio and can run standalone java projects with ease

Advertisement