java - Android Studio - AVD 说一直停止
问题描述
我需要为 uni 使用 Android Studio。所以我编写了这个基本应用程序来掌握它,但是当我在 AVD 上运行应用程序时,它说“应用程序名称一直停止。我已经多次重启 Android Studio,我已经将 AVD 管理器上的设备更改为看看这是否有任何作用,但它没有,我不确定如何解决这个问题。
*编辑我确定此信息是否有用,但是当用户单击其中一个按钮时,我试图在图像视图中显示不同的图像。我还打开了其他应用程序,它们似乎可以工作,所以只是这段代码不起作用。
这是我的 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);
}
}
};
}
这是我的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>
解决方案
你检查过日志吗?它会告诉您导致应用程序崩溃的所有问题
检查此链接。
推荐阅读
- javascript - 如何将地图结果传递给 $.ajax jQuery 函数
- postgresql - 如何将我的分钟数据划分为包含 Timescaledb 中每个月的表(PostgreSQL 扩展)
- python - 数数美国拍的电影。IndexError:列表索引超出范围
- c++ - 普通的右值引用和 std::forward 返回的有什么区别?
- jenkins - 在 jenkinsfile 中获取 github 有效负载
- ios - 如何在本机反应中使用 on-press 打开另一个文件
- javascript - 为什么我应该使用 uber 的 fusion.js 而不是 create-react-app?
- git - git filter-branch 错误:在寻找匹配的“”时出现意外的 EOF
- asp.net - CustomValidator 设置为 false,但表单仍在提交
- javascript - 在formdata中添加图像并在webservice javascript中使用