设置了新的开发环境后,我只是想开始使用它,所以我有两个简单的Android应用程序,其中只有一个简单的普通ImageView。它们具有相同的源代码(标题不同),而且令人惊奇的是第一个有效,而第二个却没有。
蜂鸣开始后,第二个应用程序立即关闭。第一个起作用并显示图像。 作为问题,我可以确定ImageView,如果删除该元素,则应用程序可以正常启动。
也许有人可以给我小费或可以帮忙。非常感谢!
AndroidStudio 3.6- 测试设备:华为Android 6.0
MainActivity.java:
Collecting torch
Killed
(bar-armor) andronikmk@instance-1:~/toxic-content-monitoring$ df -h
Filesystem Size Used Avail Use% Mounted on
udev 1.8G 0 1.8G 0% /dev
tmpfs 369M 876K 368M 1% /run
/dev/sda1 9.6G 6.1G 3.5G 64% /
tmpfs 1.8G 0 1.8G 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 1.8G 0 1.8G 0% /sys/fs/cgroup
/dev/sda15 105M 3.6M 101M 4% /boot/efi
/dev/loop0 94M 94M 0 100% /snap/core/9066
/dev/loop1 55M 55M 0 100% /snap/core18/1754
/dev/loop2 99M 99M 0 100% /snap/google-cloud-sdk/129
tmpfs 369M 0 369M 0% /run/user/1001
activity_main.xml:
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
public class MainActivity extends AppCompatActivity {
public void fade (View view){
ImageView imageView = findViewById(R.id.imageView);
imageView.animate().alpha(0).setDuration(2000);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
Logcat:
<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="0dp"
android:layout_height="0dp"
android:onClick="fade"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/bart" />
</androidx.constraintlayout.widget.ConstraintLayout>
答案 0 :(得分:0)
ID为R.id.imageView3
的ImageView不属于您的布局。因此,以下行将导致异常
ImageView imageView = findViewById(R.id.imageView3);
使用正确的ID进行更改
ImageView imageView = findViewById(R.id.imageView);
答案 1 :(得分:0)
先尝试一下,让我们看看错误是否来自xml文件
<ImageView
android:id="@+id/imageView"
android:layout_width="0dp"
android:layout_height="0dp"
app:srcCompat="@drawable/bart" />