【问题标题】:Error While launching activity in android studio after the app installation安装应用程序后在 android studio 中启动活动时出错
【发布时间】:2020-03-04 18:57:47
【问题描述】:

我在 android studio 3.5 版本中创建了一个应用,其中约束布局中只有一个图像视图。但是当我在模拟器中运行应用程序时,会显示以下错误:

显示错误:

    11/08 11:27:31: Launching 'app' on 3.7  WVGA (Nexus One) API 22.
$ adb shell am start -n "com.example.trialanderror/com.example.trialanderror.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
Error while executing: am start -n "com.example.trialanderror/com.example.trialanderror.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.example.trialanderror/.MainActivity }

Error while Launching 

XML 代码:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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=".MainActivity">

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        android:src="@drawable/beer" />
</androidx.constraintlayout.widget.ConstraintLayout>

主要活动:

package com.example.trialanderror;

import androidx.appcompat.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);

    }

  }

Android 屏幕截图:

这是 AndroidManifest.xml 文件: (当我打开它时,显示的消息是: 谷歌搜索无法索引应用程序;考虑添加至少一个带有 ACTION-VIEW 意图过滤器的活动 问题 ID:GoogleAppIndexWarning)

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

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

【问题讨论】:

  • 可以添加清单文件吗?
  • 运行 adb logcat 查看详细错误信息。确保在清单中声明了活动
  • 添加了 AndroidManifest.xml 文件

标签: android android-studio android-layout android-emulator build.gradle


【解决方案1】:

首先,在 Main Activity onCreate 中定义 Imageview。

ImageViewer imageView = (ImageViewer)findViewById(R.id.imageView);

然后确保您在 ImageViewer 中使用的图像是 .png 格式。如果问题仍然存在,请检查您的 AndroidManifest 文件。

【讨论】:

    【解决方案2】:

    确保您已将此页面放在 AndroidManifest.xml 中

    【讨论】:

    • 请告诉我如何放置它。
    • 我在问题中包含了 AndroidManifest.xml 文件
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-08-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-05
    相关资源
    最近更新 更多