ljjjjy 2020-05-08 22:00 采纳率: 0%
浏览 361
已结题

请问Android放了AdView控件调试之后又删除了,再调试就一直闪退打不开是为什么?

如题,安卓初学者,没有什么复杂功能,只是拖上去又删掉了

<?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/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.095" />

    <RadioGroup
        android:id="@+id/radioGroup"
        android:layout_width="263dp"
        android:layout_height="131dp"
        android:layout_marginStart="72dp"
        android:layout_marginTop="104dp"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/textView2">

        <RadioButton
            android:id="@+id/rbFirst"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="hh " />

        <RadioButton
            android:id="@+id/rbSecond"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="hoho" />

        <TextView
            android:id="@+id/textView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/rgText" />
    </RadioGroup>

    <Button
        android:id="@+id/btnOne"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="72dp"
        android:layout_marginTop="72dp"
        android:text="@string/txtBtnOne"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/radioGroup" />

    <CheckBox
        android:id="@+id/checkBox2"
        android:layout_width="82dp"
        android:layout_height="31dp"
        android:layout_marginTop="40dp"
        android:layout_marginEnd="12dp"
        android:text="@string/txtcb2"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/checkBox" />

    <CheckBox
        android:id="@+id/checkBox"
        android:layout_width="80dp"
        android:layout_height="33dp"
        android:layout_marginTop="56dp"
        android:layout_marginEnd="16dp"
        android:text="@string/txtcb1"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/radioGroup"
        app:layout_constraintVertical_bias="0.2" />

    <CheckBox
        android:id="@+id/checkBox3"
        android:layout_width="81dp"
        android:layout_height="30dp"
        android:layout_marginTop="64dp"
        android:layout_marginEnd="16dp"
        android:layout_marginBottom="51dp"
        android:text="@string/txtcb3"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/checkBox2"
        app:layout_constraintVertical_bias="0.0" />

    <com.google.android.gms.ads.AdView
        android:id="@+id/adView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="16dp"
        android:layout_marginBottom="16dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintStart_toStartOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>
class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        btnOne.setOnLongClickListener(View.OnLongClickListener {
            (it as Button).text = this.getString(R.string.txtBtnChanged)
            true
        })
        btnOne.setOnClickListener(View.OnClickListener {
            click2Next()
        })
        radioGroup.setOnCheckedChangeListener{
            group, checkedId ->
            textView2.text = when(checkedId){
                R.id.rbFirst -> "第一个"
                R.id.rbSecond -> "第二个"
                else ->""
            }
        }
        checkBox.setOnCheckedChangeListener(myOnCheckChangedListener)
        checkBox2.setOnCheckedChangeListener(myOnCheckChangedListener)
        checkBox3.setOnCheckedChangeListener(myOnCheckChangedListener)
    }

    fun click2Next(){
        intent = Intent(this,NextActivity::class.java).apply {
            putExtra("Label",btnOne.text)
        }
        this.startActivity(intent)
    }
    private val myOnCheckChangedListener = CompoundButton.OnCheckedChangeListener{
        buttonView, isChecked ->when(buttonView.id){
        R.id.checkBox -> {
            if(isChecked){
                checkBox.text="Checked"
            } else {
                checkBox.text = this.getText(R.string.txtcb1)
            }
        }
        R.id.checkBox2 -> {
            val temp = buttonView.text
            if(isChecked){
                checkBox2.text = "Checked"
            } else {
                checkBox2.text = this.getText(R.string.txtcb2)
            }
        }
        R.id.checkBox3 -> {
            val temp = buttonView.text
            if(isChecked){
                checkBox3.text = "Checked"
            } else {
                checkBox3.text = this.getText(R.string.txtcb3)
            }
        }
    }
    }

  • 写回答

2条回答 默认 最新

  • zqbnqsdsmd 2020-05-09 11:42
    关注
    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!