12

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.

Snapshot of the directory structure

Miguel
  • 19,133
  • 8
  • 55
  • 46
Yuya Okada
  • 149
  • 1
  • 2
  • 6

7 Answers7

20

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.

Miguel
  • 19,133
  • 8
  • 55
  • 46
12

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 {}
CopsOnRoad
  • 175,842
  • 51
  • 533
  • 380
Ahmet Arslan
  • 4,474
  • 1
  • 29
  • 32
2

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.

2

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.

sdinesh94
  • 1,068
  • 12
  • 30
2

Clean Caches

File -> Invalidate Caches / Restart...
CopsOnRoad
  • 175,842
  • 51
  • 533
  • 380
Nitya Kumar
  • 957
  • 8
  • 14
0

In your build.gradle file add the following.

android {
     sourceSets {
            main.java.srcDirs += 'src/<YOUR DIRECTORY NAME>'
        }
...
...
}
Naskov
  • 4,051
  • 5
  • 36
  • 62
0

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

mehak
  • 1