简体   繁体   English

Android Studio:会话“ app”:启动错误

[英]Android Studio: Session 'app': Error Launching activity

I have a problem with Android Studio when run the App, I have following error: 运行应用程序时,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

I tried every solutions on StackOverflow but nothing works. 我在StackOverflow上尝试了所有解决方案,但没有任何效果。 I would like to tell you that this happens to every project, for example if I created a new project and didn't do anything but click Run, I also had the following error 我想告诉您,这在每个项目中都会发生,例如,如果我创建了一个新项目并且除了单击“运行”之外什么也不做,那么我也遇到以下错误

I tried the following: 我尝试了以下方法:

  1. Reinstalled Android Studio 重新安装了Android Studio
  2. Updated SDK 更新的SDK
  3. Cleaned the project 清理项目
  4. Unchecked Instant Run 未经检查的即时运行
  5. Rebuilt the project 重建项目
  6. Changed the folder of projects 更改了项目文件夹
  7. Deleted .gradle and .idea and recreated 删除.gradle和.idea并重新创建
  8. Edit Configuration > Install Flags> -r 编辑配置>安装标志> -r

But nothing works ... 但是什么都行不通...

截图

Manifest.xml: 的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>

Layout: 布局:

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

I has the same problem and none of recommended methods worked. 我有同样的问题,没有推荐的方法有效。 Since at least in my case application still launched on emulator/phone, so I figured, that debugging still possible if you use Run->Attach debugger to android process. 由于至少在我的情况下,应用程序仍在模拟器/电话上启动,因此我认为,如果您使用Run-> Attach调试器对Android进程进行调试,则仍然可以进行调试。 The problem is that it was hard to debug startup errors. 问题是很难调试启动错误。 In that case the following method works: 在这种情况下,可以使用以下方法:

  1. run->debug app (or shift+f9) 运行->调试应用(或shift + f9)
  2. On phone message "Waiting For Debugger" pops up instead of launching application (don't click anything!!!!) 在电话消息中弹出“等待调试器”,而不是启动应用程序(请勿单击任何内容!!!!)
  3. Run->Attach debugger to android process 运行->将调试器附加到android进程
  4. Wait a bit 稍等一会
  5. Application launches with debugger attached 启动应用程序并连接调试器

That's a workaround, but worked for me. 这是一种解决方法,但对我有用。 Hope that will help. 希望对您有所帮助。

我通过手机调试时遇到了类似的问题...我关注了帖子的数量,但对我没有任何帮助...然后,我手动从Mobile手动卸载了先前安装的应用程序...然后一切正常预期!!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM