Ошибка при запуске активности в андроид студии после установки приложения - PullRequest
0 голосов
/ 08 ноября 2019

Я создал приложение в версии для 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:

enter image description here

Вот файл AndroidManifest.xml: (Когда я открыл его, отобразилось следующее сообщение: Приложение не индексируется поиском Google; рассмотрите возможность добавления хотя бы одного действия с фильтром намерений ACTION-VIEW Идентификатор проблемы: 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>

Ответы [ 2 ]

0 голосов
/ 08 ноября 2019

Сначала определите Imageview в главном действии onCreate.

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

А затем убедитесь, что изображение, которое вы используете в ImageViewer, имеет формат .png. Если проблема не устранена, проверьте файл AndroidManifest.

0 голосов
/ 08 ноября 2019

Убедитесь, что вы разместили эту страницу в AndroidManifest.xml

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...