Run single java file with standard main(String [] args) method - Android Studio

One thing that might be confusing you, like it was confusing me:

If there is the standard method to start Java application

public static void main (String[] args ) {
// your block here

}

Android Studio will automatically give an option "Run YourClass.mainActivity()", when you right-click anywhere in the editor's editing space.

Just right click in the Java file and there will be an option to run that particular Java class.


The easiest way (for me) is to do a right click in your editor and select "Run ClassName.main()". See screenshot. Using Android Studio version 1.4.1.

enter image description here


If nothing else, you can make a quick JUnit test that calls your class's main method.