【问题标题】:How to fix "Activity class does not exist" error in android? [duplicate]如何修复android中的“活动类不存在”错误? [复制]
【发布时间】:2015-11-21 10:16:16
【问题描述】:

按照 Ben in this post 的建议,我试图将我的第一个 android 项目重命名为其他项目。但是,即使按照here 的建议进行清理,在我的手机上启动应用程序时仍会出现错误(构建正常):

Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER]     cmp=com.impyiablue.stoxx/com.example.alexander.myapplication.MainActivity }
Error type 3
Error: Activity class 

我的gradle.build文件内容如下:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.1"

    defaultConfig {
        applicationId "com.impyiablue.stoxx"
        minSdkVersion 15
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    dexOptions {
        preDexLibraries = false
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.0.+'
    compile 'com.android.support:design:23.1.0'
    compile 'com.mcxiaoke.volley:library:1.0.19'
}

我的清单:

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

    <uses-permission android:name="android.permission.INTERNET" />
    <application>
        android:allowBackup="true"
        android:icon="@mipmap/stoxx"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/Theme.AppCompat.Light" />

        <activity
            android:name="com.impyiablue.stoxx.MainActivity"
            android:label="@string/app_name"
            android:theme="@style/AppTheme.NoActionBar" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <activity
            android:name="com.impyiablue.stoxx.NewEntryActivity"
            android:label="@string/menu_add"
            android:theme="@style/AppTheme.NoActionBar"
        />

    </application>

</manifest>

我还需要修改什么才能让 AndroidStudio“看到”新名称?还是有什么问题?

【问题讨论】:

  • 你的 manifest.xml 在哪里??
  • 已添加 ;-) 我手动更改了一些内容,有些项目显示为红色,例如MainActivity
  • 尝试clean and built你的项目
  • 同样的错误。活动类 {com.impyiablue.stoxx/com.example.alexander.myapplication.MainActivity} 不存在。
  • 我找到了另一个答案:stackoverflow.com/questions/8180185/… 现在我不再收到错误消息了!但是,该应用程序也无法在手机上运行!!!!!!

标签: android


【解决方案1】:

编辑application标签如下图:

 <application
    android:allowBackup="true"
    android:icon="@mipmap/stoxx"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/Theme.AppCompat.Light" >

【讨论】:

    【解决方案2】:

    活动标签在应用标签之外,因为您关闭了应用标签。

    <application> " The '>' over here should not be there"
            android:allowBackup="true"
            android:icon="@mipmap/stoxx"
            android:label="@string/app_name"
            android:supportsRtl="true"
            android:theme="@style/Theme.AppCompat.Light" /> " The '/' over here closes the application tag."
    

    您的活动标签需要包含在应用标签中。

    你的应用标签应该是这样的:

        <application
            android:allowBackup="true"
            android:icon="@mipmap/stoxx"
            android:label="@string/app_name"
            android:supportsRtl="true"
            android:theme="@style/Theme.AppCompat.Light" >
                 <activity
                    android:name="com.impyiablue.stoxx.MainActivity"
                    android:label="@string/app_name"
                    android:theme="@style/AppTheme.NoActionBar" >
                    <intent-filter>
                        <action android:name="android.intent.action.MAIN" />
                        <category android:name="android.intent.category.LAUNCHER" />
                    </intent-filter>
                </activity>
    
                <activity
                    android:name="com.impyiablue.stoxx.NewEntryActivity"
                    android:label="@string/menu_add"
                    android:theme="@style/AppTheme.NoActionBar"
                />
    </application>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-12-14
      • 2017-08-07
      • 2021-11-17
      • 1970-01-01
      • 2021-05-21
      • 1970-01-01
      • 2016-02-12
      • 2015-12-01
      相关资源
      最近更新 更多