简体   繁体   中英

Android Studio Not Finding Main Activity

I created a new class in my project called UserTypeSelection.java and wanted to set it as the main activity which launches when I run the app. I've changed the manifest file to contain an intent filter and also tried editing the configurations to set it as the default activity, however I keep receiving the error:

Error running app: The activity must be exported or contain an intent-filter

My manifest file is as follows:

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

<uses-permission android:name="android.permission.INTERNET" />

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

        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
    <activity android:name=".RegistrationActivity"></activity>
    <activity android:name=".MainActivity" />
    <activity android:name=".LoginActivity" />
    <activity android:name=".ProfileActivity" />
</application>

</manifest>

How can I resolve this issue. Any help is appreciated, thank you.

You are closing your activity xml tag before you have specified the IntentFilter .

Change your declaration to this.

<activity android:name=".UserTypeSelection" >
<intent-filter>
    <action android:name="android.intent.action.MAIN" />

    <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

UserTypeSelection must be activity and it must be using intent filters you have not closed activity after intent filter it is closed before.

Try this,

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

<uses-permission android:name="android.permission.INTERNET" />

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

        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
    </activity>
    <activity android:name=".RegistrationActivity"/>
    <activity android:name=".MainActivity" />
    <activity android:name=".LoginActivity" />
    <activity android:name=".ProfileActivity" />
</application>

</manifest>

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