提问者:小点点

我无法验证我的新activity


我为我的项目创建了一个新的空activity,但我得到了一个错误。activity文件和布局文件以红色显示。我尝试从MainActivity创建一个意图对象,以便启动此activity,但收到以下错误

分类器“Details”没有伴生对象,因此必须在此处初始化

我附上了我的android工作室的截图。

新activity代码

package com.example.safetyapp

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle

class Details : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_details)
    }

}
package com.example.safetyapp

import android.content.Intent
import android.os.Bundle
import android.widget.Button
import androidx.appcompat.app.AppCompatActivity
import com.firebase.ui.auth.AuthUI
import com.google.firebase.auth.FirebaseAuth


class MainActivity : AppCompatActivity() {

   final val AUTH_REQUEST_CODE = 7192
    lateinit var firebaseAuth:FirebaseAuth
    lateinit var listener: FirebaseAuth.AuthStateListener
    lateinit var providers: List<AuthUI.IdpConfig>

    override fun onStart(){
        super.onStart()
        firebaseAuth.addAuthStateListener(listener)

    }

    override fun onStop(){
        super.onStop()

        if(listener!=null){
            firebaseAuth.removeAuthStateListener(listener)
        }

    }


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        val button2 = findViewById<Button>(R.id.button2)
        val defence = findViewById<Button>(R.id.Defence)

        button2.setOnClickListener{

            val myintent = Intent(this, Details::class.java)

        }


        init()
    }

    private fun init() {
      providers = arrayListOf(AuthUI.IdpConfig.PhoneBuilder().build(),
              AuthUI.IdpConfig.EmailBuilder().build())

        firebaseAuth = FirebaseAuth.getInstance()
        listener = object:FirebaseAuth.AuthStateListener{
            override fun onAuthStateChanged(p0: FirebaseAuth) {
                val user = p0.currentUser
                if(user!= null){
                    // Do something
                }

                else{
                    startActivityForResult(AuthUI.getInstance()
                        .createSignInIntentBuilder()
                        .setAvailableProviders(providers)
                        .setLogo(R.drawable.logo)
                        .build(),AUTH_REQUEST_CODE)
                }
            }

        }
    }




}


共1个答案

匿名用户

试着改变

val myintent = Intent(this, Details::class.java)

val myintent = Intent(this, Details::class.kt)

因为您希望指向details.kt