简体   繁体   中英

Unresolved Class .MainActivity in Activity.xml file

I have been following some Course and suddenly I have got this error.Don't know what happened, searched on google but couldn't find the valuable answer. I have also tried invalid cached and restart but nothing happen.

Here is my Android Manifest file

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example.shoaib.miwokapp">

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme"
    tools:ignore="GoogleAppIndexingWarning">
    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name=".NmbersActivity"
        android:label="Numbers Activity" />
    <activity
        android:name=".MembersActivity"
        android:label="Members Activity" />
    <activity
        android:name=".PhrasesActivity"
        android:label="Phrases Activity" />
    <activity
        android:name=".ColorActivity"
        android:label="Color Activity" />


 </application>

</manifest>

Here is the activity_main.xml file with the error

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout
 xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:app="http://schemas.android.com/apk/res-auto"
 xmlns:tools="http://schemas.android.com/tools"
 android:layout_width="match_parent"
 android:background="#FFF7DA"
 android:orientation="vertical"
 android:layout_height="match_parent"
 tools:context="com.example.shoaib.miwokapp.MainActivity">

<TextView
    style="@style/CategoryStyle"
    android:id="@+id/clickNumber"
    android:layout_width="match_parent"
    android:layout_height="88dp"
    android:padding="12dp"
    android:background="#FD8E09"
    android:textColor="#FFFFFF"
    android:paddingLeft="16dp"
    android:paddingStart="16dp"
    android:textStyle="bold"
    android:text="@string/numbers"
    android:textSize="18sp" />


<TextView
    style="@style/CategoryStyle"
    android:id="@+id/clickMembers"
    android:layout_width="match_parent"
    android:layout_height="88dp"
    android:text="@string/family_members"
    android:textSize="18sp"
    android:background="#379237"
    android:padding="12dp"
    android:textColor="#FFFFFF"
    android:textStyle="bold"
    android:paddingLeft="16dp"
    android:paddingStart="16dp" />


<TextView
    style="@style/CategoryStyle"
    android:id="@+id/clickColor"
    android:layout_width="match_parent"
    android:layout_height="88dp"
    android:text="@string/colors"
    android:textSize="18sp"
    android:textColor="#FFFFFF"
    android:background="#8800A0"
    android:padding="12dp"
    android:textStyle="bold"
    android:paddingLeft="16dp"
    android:paddingStart="16dp" />

<TextView
    style="@style/CategoryStyle"
    android:id="@+id/clickPhrases"
    android:layout_width="match_parent"
    android:layout_height="88dp"
    android:text="@string/phrases"
    android:background="#16AFCA"
    android:textSize="18sp"
    android:textColor="#FFFFFF"
    android:textStyle="bold"
    android:padding="12dp"
    android:paddingLeft="16dp"
    android:paddingStart="16dp" />

</LinearLayout>

My build.gradle file

android {
   compileSdkVersion 28
   defaultConfig {
        applicationId "com.example.shoaib.miwokapp"
        minSdkVersion 16
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner 
"android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 
'proguard-rules.pro'
    }
}
sourceSets { main { assets.srcDirs = ['src/main/asserts', 
'src/main/assets/'] } }
}

dependencies {
  implementation fileTree(dir: 'libs', include: ['*.jar'])
  implementation 'com.android.support:appcompat-v7:28.0.0'
  implementation 'com.android.support.constraint:constraint-layout:1.1.3'
  testImplementation 'junit:junit:4.12'
  androidTestImplementation 'com.android.support.test:runner:1.0.2'
  androidTestImplementation 'com.android.support.test.espresso:espresso- 
 core:3.0.2'
 }

Thank you

Try to clean and rebuild project, also are you sure you did not place MainActivity under some directory? else you would refer like tools:context=".folderName.MainActivity" ?

activity_main.xml更改属性tool:Context = ".MainActivity"

tool:Context = "com.example.shoaib.miwokapp.MainActivity"

I encountered this type of error when I implemented chip navigation bar dependencies in my project. So when I removed the dependencies again, the error was resolved.

Right Click On MainActivity -> Click On Show In Explorerhttps://i.stack.imgur.com/6Vio6.png

Create New Folder, Name It Activity. Move MainActivity.Class into Activity Folder Your Problem Solve! https://i.stack.imgur.com/AMG3x.png

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM