启动活动时出错 [英] Error while Launching activity

查看:31
本文介绍了启动活动时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近下载了 Android Studio 2.0 并创建了一个新的启动应用程序,并没有自己添加任何代码.运行应用程序后,android studio 在模拟器上成功安装了 APK,但没有启动应用程序,而是出现以下错误:

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

我在谷歌上搜索它,发现之前有人问过它,但提供的解决方案对我也不起作用.我也没有在 AndroidManifest.xml 文件中添加任何东西.

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>

推荐答案

我今天遇到了同样的问题 [Android Studio 2.3.3, Android 8.0 on the phone]

I had exactly this same problem today [Android Studio 2.3.3, Android 8.0 on the phone]

这是我发现的.我尝试安装的应用程序未显示在 android 应用程序窗口 [您拥有所有应用程序的窗口] 中.但是一旦我进入:设置->应用程序和通知->应用程序信息,我可以看到这个屏幕截图,上面说这个应用程序没有为这个用户安装":

This is what I discovered. The app that I was trying to install was not shown in the android Application window [the one where you have them all]. But once I went in: Settings->Apps&Notifications->AppInfo I could see this screenshot where it was said that this app was "not installed for this user":

那时我进入了应用程序->点击右上角的三个点->为所有用户卸载

At that point I entered the app->clicked on the three points in the top right corner->Uninstall for all the users

现在,当我尝试通过 Android Studio 运行该项目时,错误消息消失并且应用程序已正确安装

Now when I tried to run the project through Android Studio the error message disappeared and the app was correctly installed

希望这会有所帮助,祝您有美好的一天
安东尼诺

Hope this helps, have a good day
Antonino

这篇关于启动活动时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆