1. Are you ready for the Galaxy S20? Here is everything we know so far!

Classifier 'AuthResult' does not have a companion object, and thus must be initialized here

Discussion in 'Android Development' started by Ahmad Rodzaidi Ahmad Faiz, May 20, 2021.

  1. Ahmad Rodzaidi Ahmad Faiz

    Thread Starter

    Hello All,
    I am facing a bit of a problem on kotlin android.
    I have a problem in which this warning come up : Classifier 'AuthResult' does not have a companion object, and thus must be initialized here, when I Build-> Make Project. I have placed initialization of uAuth already before function fun() below as uAuth=FirebaseAuth.getInstance() of which the text code is colored in red. See code below. But the warning still comes out. Can someone help me is it error on putting initialization at the wrong place? Or am I missing some declaration. Your most uergent help is greatly appreciated. The language below is kotlin android. Initially the code was written in javascript. And then I convert it to kotlin android using Android Studion.

    Thanks and Best Regards
    Ahmad Rodzaidi Bin Ahmad Faiz

    The below is the code of my RegisterActivity

    Code (Javascript):
    1. package com.example.shoponlinenicheteck
    2.  
    3. import android.os.Bundle
    4. import android.view.View
    5. import android.widget.Button
    6. import android.widget.EditText
    7. import android.widget.Toast
    8. import androidx.annotation.NonNull
    9. import androidx.appcompat.app.AppCompatActivity
    10. import com.google.android.gms.tasks.OnCompleteListener
    11. import com.google.android.material.textfield.TextInputLayout
    12. import com.google.firebase.auth.AuthResult
    13. import com.google.firebase.auth.FirebaseAuth
    14. import com.google.firebase.auth.FirebaseUser
    15. import com.google.firebase.database.FirebaseDatabase
    16. import org.w3c.dom.Text
    17.  
    18. class RegisterActivity : AppCompatActivity() {
    19.     var ufirstname: EditText? = null
    20.     var ulastname: EditText? = null
    21.     var uemail: EditText? = null
    22.     var upassword: EditText? = null
    23.     var uconfpassword: EditText? = null
    24.     var ucontactno: EditText? = null
    25.     var btnRegister: Button? = null
    26.     var userFirstNameWrapper: TextInputLayout? = null
    27.     var userLastNameWrapper: TextInputLayout? = null
    28.     var userEmailWrapper: TextInputLayout? = null
    29.     var userPasswordWrapper: TextInputLayout? = null
    30.     var userConfPasswordWrapper: TextInputLayout? = null
    31.     var userContactNoWrapper: TextInputLayout? = null
    32.     private var uAuth: FirebaseAuth? = null
    33.     override fun onCreate(savedInstanceState: Bundle?) {
    34.         super.onCreate(savedInstanceState)
    35.         setContentView(R.layout.activity_register)
    36.  
    37.         val ufirstname = findViewById<View>(R.id.userFirstName)
    38.         val ulastname = findViewById<View>(R.id.userLastName)
    39.         val uemail = findViewById<View>(R.id.userEmailAddress)
    40.         val upassword = findViewById<View>(R.id.userPassword)
    41.         val uconfpassword = findViewById<View>(R.id.userConfPassword)
    42.         val ucontactno = findViewById<View>(R.id.userContactNumber)
    43.  
    44.         val userFirstNameWrapper = findViewById<TextInputLayout>(R.id.userFirstNameWrapper)
    45.         val userLastNameWrapper = findViewById<TextInputLayout>(R.id.userlastNameWrapper)
    46.         val userEmailWrapper = findViewById<TextInputLayout>(R.id.userEmailWrapper)
    47.         val userPasswordWrapper = findViewById<TextInputLayout>(R.id.userPasswordWrapper)
    48.         val userConfPasswordWrapper = findViewById<TextInputLayout>(R.id.userConfPasswordWrapper)
    49.         val userContactNoWrapper = findViewById<TextInputLayout>(R.id.userContactNoWrapper)
    50.  
    51.         val btnRegister=findViewById<Button>(R.id.btnRegister)
    52.  
    53.     }
    54.  
    55.     init {
    56.         var onClick: Unit
    57.  
    58.  
    59.             run {
    60.                 if (uAuth!!.currentUser != null) {
    61.                     //User is Logged in and can redirect to another activity.
    62.  
    63.                     val firstname = ufirstname!!.text.toString().trim { it <= ' ' }
    64.                     val lastname = ulastname!!.text.toString().trim { it <= ' ' }
    65.                     val email = uemail!!.text.toString().trim { it <= ' ' }
    66.                     val password = upassword!!.text.toString().trim { it <= ' ' }
    67.                     val confpassword = uconfpassword!!.text.toString().trim { it <= ' ' }
    68.                     val contactno = ucontactno!!.text.toString().trim { it <= ' ' }
    69.                     if (firstname.isEmpty()) {
    70.                         userFirstNameWrapper!!.error = "Enter First Name"
    71.                         userFirstNameWrapper!!.requestFocus()
    72.  
    73.                     }
    74.                     if (lastname.isEmpty()) {
    75.                         userLastNameWrapper!!.error = "Enter Last Name"
    76.                         userLastNameWrapper!!.requestFocus()
    77.  
    78.                     }
    79.                     if (email.isEmpty()) {
    80.                         userEmailWrapper!!.error = "Enter Email"
    81.                         userEmailWrapper!!.requestFocus()
    82.  
    83.                     }
    84.                     if (password.isEmpty()) {
    85.                         userPasswordWrapper!!.error = "Enter Password"
    86.                         userPasswordWrapper!!.requestFocus()
    87.  
    88.                     }
    89.                     if (confpassword.isEmpty()) {
    90.                         userConfPasswordWrapper!!.error = "Enter Confirm Password"
    91.                         userConfPasswordWrapper!!.requestFocus()
    92.  
    93.                     }
    94.                     if (password != confpassword) {
    95.                         userConfPasswordWrapper!!.error = "Password didn't match"
    96.                         userConfPasswordWrapper!!.requestFocus()
    97.  
    98.                     }
    99.                     if (contactno.isEmpty()) {
    100.                         userContactNoWrapper!!.error = "Enter Contact No"
    101.                         userContactNoWrapper!!.requestFocus()
    102.  
    103.                     }
    104.  
    105.                     [COLOR=#8000ff]uAuth=FirebaseAuth.getInstance()[/COLOR]
    106.  
    107.                     fun () {
    108.                         onStart()
    109.                         super.onStart()
    110.                         //Check if user is signed in (non-null) and update UI accordingly
    111.                         val user = User(firstname, lastname, email, contactno)
    112.                         FirebaseDatabase.getInstance().getReference("Users")
    113.                             .child(FirebaseAuth.getInstance().currentUser!!.uid)
    114.  
    115.                         var onComplete: Unit
    116.  
    117.                     }
    118.                     if (AuthResult)
    119.                     uAuth= FirebaseAuth.getInstance()
    120.                     uAuth!!.createUserWithEmailAndPassword(email, password)
    121.                         .addOnCompleteListener(OnCompleteListener { AuthResult})
    122.                     var onComplete: Unit
    123.  
    124.                     var task: NonNull; Task<AuthResult?>
    125.                     (
    126.                             if (task.isSuccessful()) {
    127.                                 val user = User(firstname, lastname, email, contactno)
    128.                                 FirebaseDatabase.getInstance().getReference("Users")
    129.                                     .child(FirebaseAuth.getInstance().currentUser!!.uid)
    130.                                     .setValue(user)
    131.                                     .addOnCompleteListener(OnCompleteListener<Unit>())
    132.                                 var onComplete: Unit
    133.                                 NonNull
    134.                                 var task: Task<Void?>
    135.                                 (
    136.                                         if (task.IsSuccessful()) Toast.makeText(
    137.                                             this@RegisterActivity,
    138.                                             "User created successfully.",
    139.                                             Toast.LENGTH_LONG.show()
    140.                                         ) else
    141.                                             Toast.makeText(
    142.                                                 this@RegisterActivity,
    143.                                                 task.getException().getMessage(),
    144.                                                 Toast.LENGTH_LONG.show()
    145.                                             )
    146.                                         )
    147.                             } else Toast.makeText(
    148.                                 this@RegisterActivity,
    149.                                 task.getException().getMessage(),
    150.                                 Toast.LENGTH_LONG.show()
    151.                             )
    152.                             )
    153.  
    154.                 }
    155.  
    156.  
    157.             }
    158.  
    159.  
    160.  
    161.  
    162.     }
    163.  
    164. }
     



    1. Download the Forums for Android™ app!


      Download

       
Loading...

Share This Page

Loading...