Error while Launching activity

2020-02-01 03:45发布

I recently downloaded Android Studio 2.0 and create a new startup app and did not add anything code by myself. After running the app, android studio installs the APK on emulator successfully but does not launch the app instead it gives the following error:

$ adb shell am start -n "com.example.muhammad.firstapp/com.example.muhammad.firstapp.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER

Unexpected error while executing: am start -n "com.example.muhammad.firstapp/com.example.muhammad.firstapp.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER

Error while Launching activity

I searched it on google and found that it was asked before but the provided solution isn't working for me either. I also did not add anything in the AndroidManifest.xml file.

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.example.muhammad.firstapp">
        <application
            android:allowBackup="true"
            android:icon="@mipmap/ic_launcher"
            android:label="@string/app_name"
            android:supportsRtl="true"
            android:theme="@style/AppTheme">
            <activity android:name=".MainActivity">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
        </application>
    </manifest>

MainActivity.java

package com.example.muhammad.firstapp;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class MainActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
}

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.muhammad.firstapp.MainActivity">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!" />
</RelativeLayout>

20条回答
老娘就宠你
2楼-- · 2020-02-01 03:50

Maybe you just set your phone or emulator to refuse all the requests of installing apk through USB. Open your phone setting and change this to allow the installing. The problem is solved. Hope it works for you!

查看更多
Evening l夕情丶
3楼-- · 2020-02-01 03:51

For me, I was unable to solve the problem, which is absolutely infuriating for a piece of software as important as this. I'm a diehard Android guy, and this is frankly unacceptable, that I cannot even debug an app.

However, I did find a workaround that might help some.

For me, the Session 'app': Error Launching activity error didn't prevent the app being installed, but it did prevent debugging the app since there was no way to attach a debugger. However, there is another way.

Start the app on the phone, then click attach debugger to Android process (near the regular debug button, looks just like it), this allows you to attach a debugger to an already running app.

It's annoying as hell, but at least I can debug my app again.

查看更多
Ridiculous、
4楼-- · 2020-02-01 03:54

I've been working on this same exact problem for the last 8 hours...you've had no issues after rolling back from 2.0 to 1.5.1?

I've noticed that, even with the error, running the app works fine sometimes.

You're not alone, brother. I'll be sure to update when I figure out the solution.

Also, what are your specs? I'm running the following:

  • Windows 7
  • AMD FX(tm)-8120 8-Core

AVD:

  • Android 6.0
  • CPU/ABI: Google APIs ARM (armeabi-v7a)
  • Target: API lvl 23
  • No accelerometer
  • heapSize: 64

If you want more details, let me know. A sample size of 2 is always better than 1.

查看更多
祖国的老花朵
5楼-- · 2020-02-01 03:56

the solution is simple just uninstall package using adb command after you connect to your device

adb uninstall PACKAGE NAME

replace “PACKAGE NAME” with the name of the application you want to delete and press “Enter.”

查看更多
手持菜刀,她持情操
6楼-- · 2020-02-01 03:58

I have been install the new version 2.10 just now ,and the problem seems like to be solved.So you can try it.

查看更多
▲ chillily
7楼-- · 2020-02-01 03:58

I had the same problem, in fact the last version of my application was disabled in the phone or emulator, to solve the problem just reactivated the application in my phone (settings-> apps-> disabled) and I recompile and the problem was solved.

查看更多
登录 后发表回答