包重命名和错误“活动类不存在" [英] Package rename and error "Activity class does not exist"

查看:26
本文介绍了包重命名和错误“活动类不存在"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a splash activity which starts another activity like this

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();
    }

为了开始另一个活动,我使用 Intent 构造函数的字符串参数.对应的类和splash字符串这样配对

To start another activity I use string parameter for the Intent constructor. The corresponding class is paired with the splash string like this

   <?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>

这完美无缺,直到我重命名包名称.我通过使用重构来重命名 Manifest 中的包名称,IDE 相应地重命名所有其他类.但是当我想开始新重命名的项目时,我遇到了一个错误

This works flawlessly UNTIL I rename the package name. I rename the package name in the Manifest by using refactoring and the IDE renames all other classes accordingly. But when I want to start newly renamed project, I face an error

Launching application: com.path1.pathOLD/com.path1.path2.SplashActivity.
DEVICE SHELL COMMAND: am start -n "com.path1.pathOLD/com.path1.path2.SplashActivity"
Starting: Intent { cmp=com.path1.pathOLD/com.path1.path2.SplashActivity }
Error type 3
Error: Activity class {com.path1.pathOLD/com.path1.path2.SplashActivity} does not exist.

似乎该应用程序尝试使用 OLDpath/NEWpath.Splash 路径启动 Splash 活动并且错误在那里,但我找不到它为什么使用这样的路径.

It seems that the app tries to start the Splash activity using OLDpath/NEWpath.Splash path and the error is there, but I can't find why it is using such path.

我使用 IntelliJ IDE.有任何想法吗?它可能在清单中第二个活动的过滤器中吗?!

I use IntelliJ IDE. Any ideas? Could it be in the Filter in the 2nd activity in the Manifest?!

推荐答案

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

The error was in IntelliJ IDEA after all. When you create a project, the Configuration checks Launch feature automatically and prints the name of default class. When you change the name of package, refactoring does not change the configuration string which still points to the old class name. That is why there was not compile-time error, but runtime error.

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

It would be great if they could fix this issue in this awesome IDE as these kind of errors are very hard to track down (this one took 4 months to realize where the error was).

这篇关于包重命名和错误“活动类不存在"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆