2

Issue I am facing:

  1. Created new Java Class called "Hello"
  2. Attempted to run main method:

public class Hello {

public static void main(String[] args) {
    System.out.println("Hello World!");
    }
}

3: Error I received:

FAILURE: Build failed with an exception.

  • Where: Initialization script 'C:\Users\User25\AppData\Local\Temp\Hellos_main__.gradle' line: 21

  • What went wrong: A problem occurred configuring project ':app'.

Could not create task ':app:Hellos.main()'. SourceSet with name 'main' not found.


Things I tried: Ran the "Hello" class with coverage and works just fine. However, I have no idea why I can't simply run the code. I have probably spent a good 2 to 3 hours searching online on how to resolve this issue but couldn't find a solution. Someone had the same problem on the Android Studios forum but nobody got back with a solution. Would appreciate your help. Thanks in advance.

Link to exercise I am trying to follow

2 Answers 2

2

For running your Java code follows the following steps:

  1. Go to File > New > New Module and select Java Library
  2. Create a Java Library and add your code inside it
  3. Run the code by clicking the green arrow as follows: enter image description here

You can find more information in this link

Sign up to request clarification or add additional context in comments.

1 Comment

correct. Thanks buddy! This should be accepted answer.
1

There is no main() method in Android. the main entry point is an Activity as specified in AndroidManifest.xml (usually called MainActivity).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.