AndroidStudio : Cannot resolve symbol MainActivity
-
21-12-2019 - |
Question
I got an error "Cannot resolve symbol MainActivity" on this code.
<activity
android:name=".MainActivity" //here
android:label="@string/app_name"
android:launchMode="singleTask" >
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="MainActivity"
android:scheme="callback" />
</intent-filter>
</activity>
Needless to say , MainActivity inherits Activity and package name is correct too.
Why?
Thank you
Here's an image of the directory structure.
No correct solution
OTHER TIPS
It's possible that your 'src' directory isn't set as a source directory?
Your IDE seems to be seeing your com.example.fovoapp as a simple directory structure instead of a package. Also looking at your linked image, the little "J" on the java files tells me that also. When a java file is set as source usually it shows up as a Class "C".
I could be wrong but make sure you set your src directory as source and that should fix the issue.
package name on AndroidManifest.xml file and your classes must be same.
AndroidManifest.xml header:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.ahmet.currencies">
Code:
package com.ahmet.currencies;
import ...;
public class MainActivity extends Activity {}
Maybe you use the wrong path for the src directory.
It should be in the path : ./yourApp/src/main
and not ./yourApp/src/androidTest
You can move it manually.
project structure, right click on src folder->Mark directory as-> sources root.
Now your mainactivity.java file with 'j' symbol to change to 'c' symbol.
The error was that the project did not have a valid source folder from where it could look for the activity class.
Clean Caches
File -> Invalidate Caches / Restart...
In your build.gradle file add the following.
android {
sourceSets {
main.java.srcDirs += 'src/<YOUR DIRECTORY NAME>'
}
...
...
}
set your compatible api level. i also same the face error so i set my api level to 23 in file-> project structure-> app-> flavour -> target sdk version