[英]Error While launching activity in android studio after the app installation
我在 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>
确保您已将此页面放在 AndroidManifest.xml
首先,在主活动 onCreate 中定义 Imageview。
ImageViewer imageView = (ImageViewer)findViewById(R.id.imageView);
然后确保您在 ImageViewer 中使用的图像是 .png 格式。 如果问题仍然存在,请检查您的 AndroidManifest 文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.