met*_*ior 17 android android-studio
我最近下载了Android Studio 2.0并创建了一个新的启动应用程序,并没有自己添加任何代码.运行应用程序后,android studio成功地在模拟器上安装了APK,但没有启动应用程序,而是出现以下错误:
$ 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
Run Code Online (Sandbox Code Playgroud)
我在谷歌搜索它,发现它之前被问过,但提供的解决方案对我来说也不起作用.我也没有在AndroidManifest.xml文件中添加任何内容.
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>
Run Code Online (Sandbox Code Playgroud)
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);
}
}
Run Code Online (Sandbox Code Playgroud)
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>
Run Code Online (Sandbox Code Playgroud)
Ant*_*ino 23
我今天也遇到了同样的问题[Android Studio 2.3.3,Android 8.0在手机上]
这就是我发现的.我试图安装的应用程序没有显示在Android应用程序窗口[你拥有它们的那个].但是一旦我进入:设置 - >应用程序和通知 - > AppInfo我可以看到这个截图,据说该应用程序"未为此用户安装":
那时我进入app->点击右上角的三个点 - >为所有用户卸载
现在,当我尝试通过Android Studio运行项目时,错误消息消失,应用程序已正确安装
希望这会有所帮助,
安东尼诺度过美好的一天
小智 9
如果您使用的是Android 2.0+,请执行以下步骤:
1.运行
2.选择编辑配置..
3. 在Install Flags文本字段中输入-r
4.单击应用,然后单击确定再运行程序
测试(23/07/2016)
经过几个小时的努力,我得出结论,问题出在 AVD 中存储的用户文件上。每当我选择擦除AVD的数据时,该应用程序就会像魅力一样工作并且不会显示错误。但对于开发人员来说,每次运行应用程序之前擦除数据确实很痛苦,因为擦除数据只有在模拟器未运行时才起作用。
在另一个测试阶段,我擦除了AVD的数据,然后启动应用程序,它运行成功;但是当我第二次尝试运行该应用程序时,它再次显示该错误。
Error while Launching activity
Run Code Online (Sandbox Code Playgroud)
然后我打开“管理应用程序”并从模拟器中删除我的应用程序。但它也不起作用。
解决方法
另一种解决方法(但这对我不起作用)
定论
我认为当我们第二次尝试“运行”应用程序时,问题出在某个地方。它不会卸载应用程序的早期版本,因此当它发现包名称已存在时,它不会安装该应用程序;导致启动活动时出错。
| 归档时间: |
|
| 查看次数: |
28536 次 |
| 最近记录: |