【问题标题】:Android Studio: Session 'app': Error Launching activityAndroid Studio:会话“应用程序”:启动活动时出错
【发布时间】:2017-05-27 11:47:44
【问题描述】:

我在运行应用程序时遇到了 Android Studio 的问题,出现以下错误:

$ adb shell am start -n "com.ta94.xahmad.theerror/com.ta94.xahmad.theerror.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
Error while executing: am start -n "com.ta94.xahmad.theerror/com.ta94.xahmad.theerror.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.ta94.xahmad.theerror/.MainActivity }

Error while Launching activity

我在 StackOverflow 上尝试了所有解决方案,但没有任何效果。 我想告诉你,每个项目都会发生这种情况,例如如果我创建了一个新项目并且除了单击运行之外没有做任何事情,我也有以下错误

我尝试了以下方法:

  1. 重新安装 Android Studio
  2. 更新的 SDK
  3. 清理项目
  4. 未选中的即时运行
  5. 重建项目
  6. 更改了项目文件夹
  7. 已删除 .gradle 和 .idea 并重新创建
  8. 编辑配置 > 安装标志> -r

但没有任何效果...

Manifest.xml:

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

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity"
            android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

布局:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.ta94.xahmad.theerror.MainActivity">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</android.support.constraint.ConstraintLayout>

【问题讨论】:

  • 也许是个愚蠢的问题,但您是否尝试过清除应用数据并卸载应用? Instant Run 在应用程序缓存文件夹中保留了一些奇怪的文件,这曾经给我带来了非常奇怪的问题。
  • 我的回答可能对stackoverflow.com/a/60468450/4875245有帮助

标签: java android android-studio


【解决方案1】:

我有同样的问题,推荐的方法都没有奏效。因为至少在我的情况下,应用程序仍然在模拟器/手机上启动,所以我想,如果你使用 Run->Attach debugger to android process,调试仍然是可能的。问题是很难调试启动错误。 在这种情况下,以下方法有效:

  1. 运行->调试应用(或shift+f9)
  2. 电话留言“等待 调试器”弹出而不是启动应用程序(不要点击 任何东西!!!!)
  3. 运行->将调试器附加到android进程
  4. 等一下
  5. 应用程序启动并附加调试器

这是一种解决方法,但对我有用。希望这会有所帮助。

【讨论】:

    【解决方案2】:

    我在通过手机调试时遇到了类似的问题... 我关注了许多帖子,但对我来说没有任何结果...然后,我手动从移动设备上手动卸载了以前安装的应用程序...然后一切都按预期工作!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-07-31
      • 1970-01-01
      • 2020-03-04
      • 1970-01-01
      • 1970-01-01
      • 2021-02-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多