错误类型3错误:活动类{}不存在

本文翻译自:Error type 3 Error: Activity class {} does not exist

I have an IntelliJ Android project, that I successfully imported to Android Studio 0.4.0. 我有一个IntelliJ Android项目,该项目已成功导入到Android Studio 0.4.0。 It works perfectly if I don't change anything in manifest. 如果我不更改清单中的任何内容,它将非常有效。 However, when I want to change the launcher activity and run, it fails with this error: 但是,当我想更改启动器活动并运行时,它失败并显示以下错误:

Launching application: com.trackingeng/LandingActivity.
DEVICE SHELL COMMAND: am start -D -n "com.trackingeng/LandingActivity"  
    -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
Starting: Intent { act=android.intent.action.MAIN  
    cat=[android.intent.category.LAUNCHER] cmp=com.trackingeng/LandingActivity }
Error type 3
Error: Activity class {com.trackingeng/LandingActivity} does not exist.

When I click Sync Project with Gradle files , it outputs: 当我单击与Gradle文件同步项目时 ,输出:

Project Sync
The project 'TrackingEng' is not a Gradle-based project

Run settings: 运行设置: 在此处输入图片说明


#1楼

参考:https://stackoom.com/question/1Pl10/错误类型-错误-活动类-不存在


#2楼

I faced a similar problem after refactoring. 重构后,我遇到了类似的问题。
This is what i did to resolve this issue: 这是我为解决此问题所做的事情:

  1. Cleaned the Project 清理项目
  2. Deleted the Build directory 删除Build目录
  3. Restarted Android Studio 重新启动Android Studio
  4. Rebuild the Project 重建项目
  5. Run
  6. Optionally (Go to the files menu on android, click on "Invalidate Caches / Restart..." uninstall the app on your phone and try again) (可选)(转到android上的文件菜单,单击“无效的缓存/重新启动...”,卸载手机上的应用程序,然后重试)

And everything worked fine! 而且一切正常!
I think the key is to restart your IDE . 我认为关键是重新启动IDE

Hope this helps you or anyone else! 希望这对您或其他任何人有帮助!

Edit 1: 编辑1:
If the above steps don't work for you, then deleting Gradle cache seems to be a solution, as pointed out by @Yasitha. 如果上述步骤对您不起作用,则@Yasitha指出,删除Gradle缓存似乎是一种解决方案。

Edit 2 编辑2
As suggested by a couple of users in the comments below, sometimes the issue can be resolved by completely removing and reinstalling the app from your device. 正如一些用户在以下评论中所建议的那样,有时可以通过从设备中完全删除并重新安装该应用程序来解决该问题。
Simply type adb uninstall <package> in terminal to completely remove app from the device. 只需在终端中键入adb uninstall <package>即可从设备中完全删除应用程序。

Edit 3 编辑3
As mentioned in Abhishek's Answer , one should also try deleting the app from your device in case multiple users are set up on your device. Abhishek的答案中所述 ,如果您的设备上设置了多个用户,则还应尝试从设备中删除该应用程序。
Simply go to Mobile Settings > Apps > [Your App] > More > Uninstall App for All Users 只需转到Mobile Settings > Apps > [Your App] > More > Uninstall App for All Users

UPDATE for Android Studio 2.1 and up Android Studio 2.1及更高版本的更新

When running Android Studio 2.1 and up you can also encounter this issue when you have the instant run option enabled in your preferences (is enabled by default). 在运行Android Studio 2.1及更高版本时,如果您在首选项中启用了即时运行选项(默认情况下处于启用状态),也会遇到此问题。

To disable this option go to the Preferences option in the Android Studio top menu and look for Instant Run so you can uncheck the first checkbox on that screen. 要禁用此选项,请转到Android Studio顶部菜单中的Preferences选项Preferences选项,然后查找“ Instant Run以便您可以取消选中该屏幕上的第一个复选框。

在Android Studio 2.1+中禁用即时运行

Anyway that fixed it for me. 无论如何,它为我解决了。 Originally pointed out by user @yusufonder. 最初由用户@yusufonder指出。 I discovered this was the issue since gradle install still worked. 我发现这是问题,因为gradle安装仍然有效。


#3楼

Try changing the name of the Activity in your AndroidManifest.xml file. 尝试在AndroidManifest.xml文件中更改“活动”的名称。

Right now it says: 现在它说:

<activity android:name="LandingActivity" >

Try either adding a period to the beginning of the Activity's name: 尝试在活动名称的开头添加句点

<activity android:name=".LandingActivity" >

Or adding the package name to the beginning of the Activity's name: 将包名称添加到活动名称的开头:

<activity android:name="com.trackingeng.LandingActivity" >

It also may be a problem that your package name has only two components separated by periods (your package name is "com.trackingeng"; a more standard package name would be "com.trackingeng.app") 您的软件包名称中只有两个由句点分隔的部分也可能是一个问题(您的软件包名称为“ com.trackingeng”;更标准的软件包名称为“ com.trackingeng.app”)


#4楼

I had the same error after renaming/refactoring. 重命名/重构后出现相同的错误。 What I did was add the applicationId property attribute to my build.gradle file, and set its value to the application package. 我所做的是将applicationId属性属性添加到我的build.gradle文件中,并将其值设置为应用程序包。

In build.gradle : build.gradle中

android {
defaultConfig {
    applicationId "com.example.myapp"  
  }
}

#5楼

This happens when you do the following 当您执行以下操作时,会发生这种情况

  • connect your device/emulator 连接您的设备/仿真器
  • run the app from Android Studio (AS) 从Android Studio(AS)运行应用
  • use/test the app and uninstall it from the device while it is still connected to your computer 使用/测试该应用,并在该设备仍连接到计算机时将其从设备上卸载
  • try to run the app again from AS 尝试从AS重新运行该应用

AS thinks you still have the app in your device. AS认为您的设备中仍然有该应用程序。

tl;dr - To resolve this, you can simply disconnect your device after uninstalling the app and reconnect it. tl; dr-要解决此问题,只需在卸载应用程序后重新连接设备并断开连接即可。


#6楼

我遇到了同样的问题,我解决了它,可以重构活动启动器,只需更改类名即可。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
声明:这些内容是逐步总结过来的,所以可能有当时的理解不正确,只希望大家能做个参考: 内容如下: 目录 一句话总结汇总: Copy project into workspace 和add project into work set 的含义 数字签名总结 JNI 基础及注意: Ndk的使用方法: Ant 与 android update project 命令行只有在非根盘符上才能运行 android Launcher Android 运行环境搭建 Android:name什么时候加”.” Activity class {package/class} does not exist 问题的解决 Activity 中两次调用OnCreate的原因 ByteBuffer 和 FloatBuffer 的直接分配和非直接分配 Application的使用小总结 “call to OpenGL ES API with no current context (logged once per thread” 问题的解决 2013年9月7日19:15:33:我的平板分辨率很高可是运行public void onSurfaceChanged(GL10 gl, int width, int height)函数时,分辨率只有 455*320,这是为什么? 关于android添加第三方字体的方法 android-apt-compiler: [t1] res\layout\LinearLayout.xml: Invalid file name: must contain only [a-z0-9_.] Buttons in button bars should be borderless android 支持的距离单位 使用adb shell命令进入手机后使用ls命令提示: opendir failed permission denied 使用adb pull 命令提示permission denied Button 中的setLayoutParams使用注意: layout文件夹和raw文件下面的文件读取 Matrix方法中的set方法和post方法 android 中调用drawBitmap时理解dip(屏幕密度)和px(像素)的区别 SQLiteDatabase 的setTransactionSuccessful作用 终于弄明白 paddingleft margineleft layout_gravity 和gravity之间的区别 自定义控件时要注意的问题。 obtainMessage 的作用: FrameLayout 需要注意的地方: EditText 禁止弹出按键盘: 获取控件屏幕位置和窗口位置: 为什么MyAdapater的getView没有被调用 XmlSerializer使用总结: ListView中的Item自定义点击后的背景色的方法。 drawable各个分辨率 fragment 的几种创建方式 fragment第一次使用遇到的问题 activity变身对话框 onMeasure 中的AT_MOST EXACTLY UNSPECIFIED MotionEvent的触发记录 对于Drawable 的 getIntrinsicHeight 和getIntrinsicWidth的理解 IntentService 使用总结: 文件读写总结: AES 解密失败: XML中的include标签加入后崩溃 Button的background标签使图像拉伸的问题 SharedPreferences 的getString 的陷阱 TextView 中的EMS和Maxlength

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值