0

I am continually getting the error default activity not found in android studio. I have updated the

sourceSets {
    main.java.srcDirs += 'src/main/<YOUR DIRECTORY>'
} to -


sourceSets {
    main.java.srcDirs += 'src/main/home/adarsh/Desktop/Desktop/android-studio/jre'
      } 

As mentioned here.How to add a linked source folder in Android Studio?

But I am getting the same error again ,please tell me what else needed to done to avoid the error default activity not found in Android studio.

A.kumar
  • 27
  • 6
  • `'src/main/'`?? did your change the `` with your directory?? – Rod_Algonquin Jun 11 '17 at 03:07
  • Why not just put your source in the default location, `/app/src/main/java` ? And please tell me you don't keep your Java source files in the `jre` directory. – nasch Jun 11 '17 at 03:57
  • of course@Rod_Algonquin , I changed that to "src/main/home/adarsh/Desktop/Desktop/android-studio/jre" , any other suggestion. – A.kumar Jun 11 '17 at 07:26
  • @nasch , may you tell how to "put your source in the default location, /app/src/main/java ". I installed the Android studio and am trying to run my first hello world app . I tried "which java " whose output is /usr/bin/java. – A.kumar Jun 11 '17 at 07:32
  • @Rod_Algonquin , I set the main.java.srcDirs as- main.java.srcDirs += 'src/main/home/adarsh/AndroidStudioProjects/MyApplication/app/src/main/java/MyApplication.java' . Is this correct ? I am not able to resolve the error yet. – A.kumar Jun 20 '17 at 14:09
  • @A.kumar `main.java.srcDirs` means the file directory of the source code, not the JRE file – Rod_Algonquin Jun 20 '17 at 14:33
  • @Rod_Algonquin I placed main.java.srcDirs += '/usr/lib/jvm/java-8-oracle', Is this wrong ? I aslo tried by placing main.java.srcDirs += '/usr/lib/jvm/java-8-oracle/bin/java' , but still getting the same error. Please help me to figure it out. – A.kumar Jun 22 '17 at 04:39

2 Answers2

0

which java tells you where your installation of the java platform is. You should put your source files, such as HelloWorld.java or MainActivity.java, in the location I indicated. The easiest way to do this is to go to Android Studio's project view and select the Android tab. Then open the app node, right click java, and add a new class. It will automatically be put in the right place. Remove everything about sourceSet from your build file.

nasch
  • 5,330
  • 6
  • 31
  • 52
  • I did the same as you told added a class and removed everything from sourceSet ,but still getting the same error . Is some thing needed to be add in the newly created class ? I am very beginner , any help is highly appreciated . – A.kumar Jun 20 '17 at 16:13
  • Have you specified your startup activity in the manifest? https://stackoverflow.com/questions/9704898/how-to-set-my-activity-as-main-activity-in-android – nasch Jun 23 '17 at 02:03
  • Thanks @nasch , btw I solved it and posted as an answer. – A.kumar Jun 23 '17 at 08:10
0

I solved the problem by uninstalling and then reinstalling Android studio(to set all the paths again ).

The problem I found was "JAVA_HOME" was not set as an environment variable (I downloaded the latest jdk from oracle and indicated it's path as JAVA_HOME ).

Once I added the JAVA_HOME as my environment variable by editing the ./bashrc the new installed Android studio automatically sets the jdk path same as "JAVA_HOME".

Thanks

A.kumar
  • 27
  • 6