应用安装后在android studio中启动活动时出错

我在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屏幕截图:

应用安装后在android studio中启动活动时出错

这是AndroidManifest.xml文件: (当我打开它时,显示的消息是: 该应用无法通过Google搜索建立索引;考虑使用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>
heculestong 回答:应用安装后在android studio中启动活动时出错

确保已将该页面放置在AndroidManifest.xml中

,

首先,在Main活动onCreate中定义Imageview。

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

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

本文链接:https://www.f2er.com/3139868.html

大家都在问