0

I searched for this question already but there were no answers that worked for me. Every time I debug my app it gives me this error.

Unexpected error while executing: am start -n "com.example.maomei.passusersystem/com.example.maomei.passusersystem.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER -D
Error while Launching activity

Here is my MainActivity code:

public class MainActivity extends AppCompatActivity {

    TextView textView1;
    Button button1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        TextView textView1 = (TextView) findViewById(R.id.textView1);
        Button button1 = (Button) findViewById(R.id.button1);

        button1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                switch (v.getId()){
                    case R.id.button1:

                        Intent myIntent = new Intent(MainActivity.this, Main2Activity.class);
                        MainActivity.this.startActivity(myIntent);


                    }


            }


        });
    }
}

and my Manifest code:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.maomei.passusersystem">
    <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="com.example.maomei.passusersystem.MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".Main2Activity"
            android:label="@string/title_activity_main2"
            android:theme="@style/AppTheme.NoActionBar" />
        <activity
            android:name=".Main4Activity"
            android:label="@string/title_activity_main4"
            android:theme="@style/AppTheme.NoActionBar" />
        <activity
            android:name=".Main5Activity"
            android:label="@string/title_activity_main5"
            android:theme="@style/AppTheme.NoActionBar">

        </activity>
    </application>
</manifest>
BSMP
  • 4,596
  • 8
  • 33
  • 44
Mira
  • 23
  • 6

4 Answers4

1

I realize this question is a couple of years old, but I was having the same problem and I resolved it after reading another stack overflow thread. Try rebuilding the project after deleting the .gradle and .idea directories. Session 'app': Error Launching activity

Katelyn C.
  • 11
  • 1
-1

Try changing the android:name attribute of MainActivity in your manifest file to just .MainActivity

DaveNOTDavid
  • 1,753
  • 5
  • 19
  • 37
-1

Can you try this without passing the -a -c argument adb shell am start -n com.package.name/com.package.name.ActivityName

-1

Mira, I just created a new android app using empty activity template, added 1 more activity for checking and below are files that have same code as yours but doesn't have any error.

Only difference is my manifest file has manifest tag which is not present in yours.

Delete the project, recreate the project and copy paste your code safely to the newly generated project.

Manifest file

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

    <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">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

MainActivity class

package com.example.maomei.passusersystem;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

    TextView textView1;
    Button button1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        TextView textView1 = (TextView) findViewById(R.id.textView1);
        Button button1 = (Button) findViewById(R.id.button1);

        button1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                switch (v.getId()){
                    case R.id.button1:

                        Intent myIntent = new Intent(MainActivity.this, Main2Activity.class);
                        MainActivity.this.startActivity(myIntent);


                }


            }


        });
    }
}
JRG
  • 4,037
  • 3
  • 23
  • 34
  • I did not work sadly. It show me the first activity and then says that the app is not responding. Also, it gives me the same error. If you have another solution it would be great if you could share it with me. Thank you anyways. – Mira Jul 05 '17 at 17:35
  • No matter how big or small the project is, this is not considered good practice for resolving issues since it proves such minimal effort. – DaveNOTDavid Jul 05 '17 at 17:35
  • Mira, if possible, can you push your code to github so that i can checkout your code and check whats the issue? – JRG Jul 05 '17 at 22:12
  • Hello down voter, I will appreciate if you could vote up to neutralize your vote till Mira updates with more details as I am looking to help stackoverflow peer if more details are provided. – JRG Jul 10 '17 at 07:21