Android 包重命名和错误";“活动类不存在”;

Android 包重命名和错误";“活动类不存在”;,android,intellij-idea,android-intent,intentfilter,Android,Intellij Idea,Android Intent,Intentfilter,我有一个splash活动,它启动了另一个类似这样的活动 public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.splash); final Thread splashThread = new Thread() { @Override p

我有一个splash活动,它启动了另一个类似这样的活动

public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.splash);

        final Thread splashThread = new Thread() {
            @Override
            public void run() {
                try {
                    int wait = 0;
                    while (_isActive && (_splashTime > wait)) { 
                        sleep(100);

                        if (_isActive) {
                            wait += 100;
                        }
                    }
                } catch (InterruptedException e) {
                    Log.d(TAG, e.getMessage());

                } finally {
                    startActivity(new Intent("com.path1.path2.SomeActivity"));
                    finish();
                }
            }
        };
        splashThread.start();
    }
   <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.path1.path2"
          android:versionCode="2"
          android:versionName="1.0">
    <uses-sdk android:minSdkVersion="4"/>

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

    <application android:label="@string/app_name" android:icon="@drawable/icon">
        <activity android:name=".SplashActivity"
                  android:label="@string/app_name"
                >
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
        <activity android:name=".SomeActivity"
                  android:label="@string/app_name"
                >
            <intent-filter>
                <action android:name="com.path1.path2.SomeActivity"/>
                <category android:name="android.intent.category.DEFAULT"/>
            </intent-filter>
        </activity>
        <activity android:name=".OtherActivity" android:label="@string/app_name"
                />

        <!--services-->
        <service android:name=".AlarmService"/>

    </application>
</manifest>
要启动另一个活动,我使用
Intent
构造函数的字符串参数。相应的类与如下所示的启动字符串配对

public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.splash);

        final Thread splashThread = new Thread() {
            @Override
            public void run() {
                try {
                    int wait = 0;
                    while (_isActive && (_splashTime > wait)) { 
                        sleep(100);

                        if (_isActive) {
                            wait += 100;
                        }
                    }
                } catch (InterruptedException e) {
                    Log.d(TAG, e.getMessage());

                } finally {
                    startActivity(new Intent("com.path1.path2.SomeActivity"));
                    finish();
                }
            }
        };
        splashThread.start();
    }
   <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.path1.path2"
          android:versionCode="2"
          android:versionName="1.0">
    <uses-sdk android:minSdkVersion="4"/>

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

    <application android:label="@string/app_name" android:icon="@drawable/icon">
        <activity android:name=".SplashActivity"
                  android:label="@string/app_name"
                >
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
        <activity android:name=".SomeActivity"
                  android:label="@string/app_name"
                >
            <intent-filter>
                <action android:name="com.path1.path2.SomeActivity"/>
                <category android:name="android.intent.category.DEFAULT"/>
            </intent-filter>
        </activity>
        <activity android:name=".OtherActivity" android:label="@string/app_name"
                />

        <!--services-->
        <service android:name=".AlarmService"/>

    </application>
</manifest>
应用程序似乎试图使用
OLDpath/NEWpath.Splash启动启动活动,但出现了错误,但我找不到它为什么使用这样的路径


我使用intellijide。有什么想法吗?它可能在清单中第二个活动的筛选器中吗

您是否注意到这一差异(对于清单中的包名),

启动活动是
com.path1.pathOLD/com.path1.path2.SplashActivity。

更改清单文件中的包。。使用此修改的清单并让我知道发生了什么

编辑:修改清单文件

<?xml version="1.0" encoding="utf-8"?>
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.path1.path2"
      android:versionCode="2"
      android:versionName="1.0">
<uses-sdk android:minSdkVersion="4"/>

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

<application android:label="@string/app_name" android:icon="@drawable/icon">
    <activity android:name=".SplashActivity"
              android:label="@string/app_name"
            >
        <intent-filter>
            <action android:name="android.intent.action.MAIN"/>
            <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>
    </activity>
    <activity android:name=".SomeActivity"
              android:label="@string/app_name"
            >
        <intent-filter>
           <category android:name="android.intent.category.DEFAULT"/>
        </intent-filter>
    </activity>
    <activity android:name=".OtherActivity" android:label="@string/app_name"
            />

    <!--services-->
    <service android:name=".AlarmService"/>

</application>


毕竟,错误在IntelliJ IDEA中。创建项目时,配置会自动检查启动功能并打印默认类的名称。当您更改包的名称时,重构不会更改仍然指向旧类名的配置字符串。这就是为什么没有编译时错误,而是运行时错误

如果他们能在这个很棒的IDE中解决这个问题,那就太好了,因为这些错误很难追踪(这一次花了4个月才意识到错误在哪里)


我在
AndroidManifest.xml
中的Eclipse/ADT中收到了相同的错误消息(通常是当两个人使用不同的IDE在同一个项目上工作时),并通过将包名添加到活动名的开头来修复它

在本例中,这意味着要更改以下内容:

<activity android:name=".SplashActivity"

我遇到了这个问题,这是因为清单文件中存在问题。确保您的清单文件没有任何问题。

这是Android Studio中的一个bug。要解决此问题,请执行以下操作:

  • 关闭工作室
  • Remove.idea/workspace.xml
  • 发射室

  • 在我的情况下,我遵循了这里的所有答案,但我也必须清理缓存。我遵循以下步骤:

    1. Go to ~/.gradle/ and delete caches folder
       rm -r caches
    2. "Sync project with Gradle files" icon on Android Studio
    3.  Run project
    

    我也有同样的问题。在尝试了这个线程中的所有内容后,结果是Android Studio的即时运行


    禁用此选项可以立即修复此问题,删除.android/build缓存下的所有内容(如果可以找到特定版本)也可以解决此问题。原因是instant run似乎使用了应用程序的缓存版本,在定期清理/重建过程中甚至没有删除该版本。

    我也遇到了这个问题,特别是在切换口味时。所以对我来说,解决这个问题的办法是禁用android中的即时运行。 关于这一点,我想包括一些要点-

    • 确保你的舱单没有问题
    • 最大限度地清洁项目和重建项目将解决问题
    • 禁用2.1以上的android studio中的即时运行
    • 卸载应用程序并重新安装

    确保您的包名在Gradle、Manifest中相同。
    转到模块设置->口味->应用程序ID->(您的软件包名称)

    文件->无效缓存/重新启动
    可能会修复此类错误

    重命名软件包后,我还遇到以下错误:

    启动程序活动com.path1.abc/com.path2.abc.SplashActivity不执行 不存在

    我确保包名已更新,并且还包括这些文件

    • google_services.json
    • AndrodiManifest.xml
    • build.gradle

    最后卸载了以前的应用程序,清理并运行项目。这对我很有用。

    啊!!!我们都有答案,但我花了一段时间描述了整个答案,更不用说+1了。我认为这是唯一的问题。@Lalit Poptani-我认为,在清单文件中有问题,也请看这一行。@user370305我还认为问题在过滤器中。但是,如果我相应地重命名了两个字符串路径,为什么它不起作用呢。它通常可以工作,但只有在重命名包名后才可以工作。@user370305正如我告诉Lalit的,错误不在活动名称的清单中,而是我的输入错误。很抱歉请更正您的答案,以便我们不会混淆其他人。谢谢,你的问题是否解决了?请来到临时聊天室,这样我们就可以在那里讨论你的问题。好的,只需在清单文件中更改包名,写下这个“com.path1.pathOLD”,然后再次运行你的应用程序,让我知道发生了什么…我想,Eclipse在启动应用程序时内置了更新包名的任务。这在一个伟大的IDE中是一个可怕的错误。我从Eclipse转到IntelliJ,在这个bug出现之前,我没有遇到任何问题。谢谢你为我们其他人回答你自己的问题。你是一个很好的社区成员。非常感谢你回答自己的问题。我添加了我想首先开始的新活动,但IntelliJ IDEA一直说我必须添加到旧活动中。解决方案是设置单选按钮以启动默认活动找到解决方案的好工作。我在运行>编辑配置的顶部菜单中找到了您显示的屏幕,在更改为“启动默认活动”后,项目运行。谢谢。“启动默认活动”选项处于活动状态,似乎在内部找到了错误的活动,因此现在我手动选择了启动活动,尽管在这个线程中尝试了其他所有操作,但在我也这么做之前,我仍然没有运气。这修复了安卓Studio 1.0的问题。谢谢在我看来,这个答案比贴出的最佳答案要好。在我的例子中,我也删除了.idea的两个目录。我不得不关闭工作室并导入Gradle项目,检测到我所做的许多更改