简体   繁体   English

Android Studio - AVD 说一直停止

[英]Android Studio - AVD says keeps stopping

I need to use Android Studio for uni.我需要为 uni 使用 Android Studio。 So i coded this basic app to get the hang of it but when I run the app on the AVD, it says that the " app name keeps stopping. I have restart Android Studio multiple times and I have the changed the device on AVD manager to see if that does anything but it does not, I'm unsure how to fix this.所以我编写了这个基本应用程序来掌握它,但是当我在 AVD 上运行应用程序时,它说“应用程序名称一直停止。我已经多次重启 Android Studio,我已经将 AVD 管理器上的设备更改为看看这是否有任何作用,但它没有,我不确定如何解决这个问题。

*edit I'm sure if this information is helpful but I'm trying to show a difference image in the imageview when the user clicks one of the buttons. *编辑我确定此信息是否有帮助,但是当用户单击其中一个按钮时,我试图在 imageview 中显示差异图像。 I also open other apps and they seem to work so it is just this code that wouldn't work.我还打开了其他应用程序,它们似乎可以工作,所以只是这段代码不起作用。

Here is my MainActivity.java code:这是我的 MainActivity.java 代码:

  package com.example.teavelapp;



public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    RadioButton rb0 = (RadioButton) findViewById(R.id.radioButton);
    rb0.setOnClickListener(radioGroupClick);

    RadioButton rb1 = (RadioButton) findViewById(R.id.radioButton2);
    rb1.setOnClickListener(radioGroupClick);

    RadioButton rb2 = (RadioButton) findViewById(R.id.radioButton3);
    rb2.setOnClickListener(radioGroupClick);

}

private View.OnClickListener radioGroupClick = new View.OnClickListener() {
    public void onClick(View view) {
        RadioButton rb = (RadioButton) view;
        ImageView iv = (ImageView) findViewById(R.id.imageView);

        if (rb.getText().equals("Hopewell Rocks")) {
            iv.setImageResource(R.drawable.hopewell_rocks);
        } else if (rb.getText().equals("Niagara Falls")) {
            iv.setImageResource(R.drawable.niagara_falls);
        } else if (rb.getText().equals("Parliament Hill")) {
            iv.setImageResource(R.drawable.parliament_hill);
        }

    }
};

}

and here is my xml code:这是我的 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">

<TextView
    android:id="@+id/textView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/canadain_landmarks"
    android:textColor="#2B2B2B"
    android:textSize="30sp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintVertical_bias="0.049" />

<RadioGroup
    android:id="@+id/radioGroup"
    android:layout_width="244dp"
    android:layout_height="237dp"
    android:layout_marginStart="54dp"
    android:layout_marginLeft="54dp"
    android:layout_marginTop="24dp"
    android:layout_marginEnd="46dp"
    android:layout_marginRight="46dp"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.432"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/textView">

    <RadioButton
        android:id="@+id/radioButton"
        android:layout_width="match_parent"
        android:layout_height="85dp"
        android:text="@string/hopewell_rocks"
        android:textSize="18sp" />

    <RadioButton
        android:id="@+id/radioButton2"
        android:layout_width="match_parent"
        android:layout_height="74dp"
        android:text="@string/niagara_falls"
        android:textSize="18sp" />

    <RadioButton
        android:id="@+id/radioButton3"
        android:layout_width="match_parent"
        android:layout_height="92dp"
        android:text="@string/parliament_hill"
        android:textSize="18sp" />

</RadioGroup>

<ImageView
    android:id="@+id/imageView2"
    android:layout_width="406dp"
    android:layout_height="165dp"
    android:layout_marginBottom="82dp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:srcCompat="@drawable/flag" />

     </androidx.constraintlayout.widget.ConstraintLayout>

this is what my device shows when I try to run it这是我尝试运行设备时显示的内容

Did you check the log?你检查过日志吗? It tells you all about the problem that caused your app to crash它会告诉您导致应用程序崩溃的所有问题

Check this link .检查此链接

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM