简体   繁体   English

为什么我会收到默认的 Activity not found 错误?

[英]Why am I getting a default Activity not found error?

I have used intent-filter here:我在这里使用了intent-filter

<intent-filter>
    <action android:name="android.intent.action.MAIN"/>
    <action android:name="com.example.test.testActivity"/>
    <category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>

I invalidated and restarted several times, but it failed.我多次失效并重新启动,但它失败了。

I used Micer´s method to do things like this我用 Micer 的方法做这样的事情

android {
    ....
    ....

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

But it still has the error Default Activity not found但它仍然有错误未找到默认活动

android {
    compileSdkVersion 24
    buildToolsVersion "25.0.2"
    defaultConfig {
        applicationId "com.example.test"
        minSdkVersion 15
        targetSdkVersion 24
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
}



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

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".testActivity"></activity>/>

        <intent-filter>
            <action android:name="android.intent.action.MAIN"/>
            <action android:name="com.example.test.testActivity"/>
            <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>


    </application>

</manifest>

and I think this maybe the source:我认为这可能是来源:

 <activity android:name=".testActivity"></activity>/>

error:Reports empty tag body.错误:报告空标签正文。 The validation works in XML / JSP / JSPX / HTML/ XHTML file types.验证适用于 XML/JSP/JSPX/HTML/XHTML 文件类型。

How can I solve this issue?我该如何解决这个问题?

The intent-filter goes INSIDE your activity TAG to make it the default like so: intent-filter进入您的activity标签内部,使其成为默认值,如下所示:

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

    </application>
</manifest>

Replace this,换这个,

<activity android:name=".testActivity"></activity>/>

        <intent-filter>
            <action android:name="android.intent.action.MAIN"/>
            <action android:name="com.example.test.testActivity"/>
            <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>  

with this,有了这个,

<activity android:name=".testActivity">

                <intent-filter>
                    <action android:name="android.intent.action.MAIN"/>
                    <action android:name="com.example.test.testActivity"/>
                    <category android:name="android.intent.category.LAUNCHER"/>
                </intent-filter>
        </activity>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么我的片段未附加到活动错误? - Why am I getting Fragment not Attached to Activity Error? 为什么我在android中的活动出错? - Why I am getting error with my activity in android? 为什么运行Google Maps活动时出现此错误? - Why i am getting this error while running google maps activity? 为什么在Android的ExifInterface上出现File not found错误? - Why am I getting File not found error for ExifInterface with Android? 为什么在Cordova Firebase插件中找不到AbstractSafeParcelable错误 - Why am I getting AbstractSafeParcelable not found error in Cordova Firebase plugin 为什么我收到错误没有为 MediaController(ClassNAme) 找到合适的构造函数? - Why I am getting an Error No suitable constructor found for MediaController(ClassNAme )? 为什么在此活动中出现空对象错误? - Why am getting null object error in this activity? 为什么我没有找到测试? - Why Am I getting no tests found? Android Studio 3.5 ...升级后未找到错误默认活动 - Android Studio 3.5 ...Getting the error default activity not found after upgraded 我经常发现此特定错误:“无法识别启动活动:找不到默认活动启动活动时出错” - I often found this specific error: “Could not identify launch activity: Default Activity not found Error while Launching activity”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM