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

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

<?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个回答

kotlin没用过,不过看了下应该是kotlin自动绑定了adview的id,删除后找不到报错,clean一下工程应该就可以

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐