Мое приложение вылетает при открытии «Активность в комнате». Я прикрепил свой манифест, а также результаты действий и logcat. Я не понимаю, в чем здесь настоящая проблема. Я внес изменения в соответствии со статьями в Интернете, но все равно получаю ту же ошибку.

Android-манифест

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.tictactoe">

    <uses-permission android:name="android.permission.INTERNET"/>

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.TicTacToe">
        <activity android:name=".OnlineGameActivity"></activity>
        <activity android:name=".RoomActivity" />
        <activity android:name=".FriendsActivity" />
        <activity android:name=".ComputerActivity" />
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

Файл активности комнаты

package com.example.tictactoe

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Toast
import com.google.firebase.auth.FirebaseAuth
import com.google.firebase.database.FirebaseDatabase
import kotlinx.android.synthetic.main.activity_room.*


class RoomActivity : AppCompatActivity() {

    var mAuth: FirebaseAuth?=null
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_room)
        mAuth = FirebaseAuth.getInstance()
        buLoginEvent()
    }

    fun buLoginEvent(){
       LoginToFirebase(email.text.toString(), password.text.toString());

    }

    fun LoginToFirebase(email:String, password:String){


        var database = FirebaseDatabase.getInstance()
        var myRef = database?.reference
        var currentUser = mAuth!!.currentUser
        mAuth!!.createUserWithEmailAndPassword(email,password)
            .addOnCompleteListener(this){
                task->
                if(task.isSuccessful){
                    Toast.makeText(applicationContext,"Successfull Login", Toast.LENGTH_LONG).show()
                    //saving in database
                    myRef.child("Users").child(splitString(currentUser!!.email.toString())).setValue(
                        currentUser!!.uid
                    )//creating current node iin relatime database
                    LoadMain()
                }
                else{
                    Toast.makeText(applicationContext,"Failed Login", Toast.LENGTH_LONG).show()
                }
            }

    }

    override fun onStart() {//2nd time when the application is started then call this method
        super.onStart()
        LoadMain()
    }
    fun  LoadMain(){
        var currentUser = mAuth!!.currentUser

        if(currentUser!=null) {// doing this only when the user is not null


            var intent = Intent(this, OnlineGameActivity::class.java)
            intent.putExtra("email", currentUser!!.email)
            intent.putExtra("uid", currentUser!!.uid)

            startActivity(intent)
            finish()
        }
        else{

        }
    }
    fun splitString(str:String):String{
        var split=str.split("@")
        return split[0]
    }
}

OnlineGameActivity

package com.example.tictactoe

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import android.widget.Button



import com.google.firebase.analytics.FirebaseAnalytics
import com.google.firebase.database.DataSnapshot
import com.google.firebase.database.DatabaseError
import com.google.firebase.database.FirebaseDatabase
import com.google.firebase.database.ValueEventListener
import kotlinx.android.synthetic.main.activity_online_game.*
import kotlin.collections.HashMap




class OnlineGameActivity : AppCompatActivity() {
    //database instance


    var myEmail:String?=null

    private var mFirebaseAnalytics: FirebaseAnalytics?=null
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_online_game)
        mFirebaseAnalytics= FirebaseAnalytics.getInstance(this)

        IncommingCalls()
    }


    protected  fun buClick(view: View){
        val buSelected= view as Button
        var cellID=0
        when(buSelected.id){
            R.id.bu1-> cellID=1
            R.id.bu2-> cellID=2
            R.id.bu3-> cellID=3
            R.id.bu4-> cellID=4
            R.id.bu5-> cellID=5
            R.id.bu6-> cellID=6
            R.id.bu7-> cellID=7
            R.id.bu8-> cellID=8
            R.id.bu9-> cellID=9

        }
        // Toast.makeText(this,"ID:"+ cellID, Toast.LENGTH_LONG).show()
        var database = FirebaseDatabase.getInstance()
        var myRef = database?.reference
        myRef.child("PlayerOnline").child(sessionID!!).child(cellID!!.toString()).setValue(myEmail)
    }

    var player1= java.util.ArrayList<Int>()
    var player2= java.util.ArrayList<Int>()
    var ActivePlayer=1

    fun PlayGame(cellID:Int,buSelected:Button){

        if(ActivePlayer==1){
            buSelected.text="X"
            //buSelected.setBackgroundResource(R.color.blue)
            player1.add(cellID)
            ActivePlayer=2

        }else{
            buSelected.text="O"
           // buSelected.setBackgroundResource(R.color.darkgreen)
            player2.add(cellID)
            ActivePlayer=1
        }


        buSelected.isEnabled=false
        CheckWiner()
    }



    fun  CheckWiner(){
        var winer=-1

        // row 1
        if(player1.contains(1) && player1.contains(2) && player1.contains(3)){
            winer=1
        }
        if(player2.contains(1) && player2.contains(2) && player2.contains(3)){
            winer=2
        }


        // row 2
        if(player1.contains(4) && player1.contains(5) && player1.contains(6)){
            winer=1
        }
        if(player2.contains(4) && player2.contains(5) && player2.contains(6)){
            winer=2
        }




        // row 3
        if(player1.contains(7) && player1.contains(8) && player1.contains(9)){
            winer=1
        }
        if(player2.contains(7) && player2.contains(8) && player2.contains(9)){
            winer=2
        }



        // col 1
        if(player1.contains(1) && player1.contains(4) && player1.contains(7)){
            winer=1
        }
        if(player2.contains(1) && player2.contains(4) && player2.contains(7)){
            winer=2
        }



        // col 2
        if(player1.contains(2) && player1.contains(5) && player1.contains(8)){
            winer=1
        }
        if(player2.contains(2) && player2.contains(5) && player2.contains(8)){
            winer=2
        }


        // col 3
        if(player1.contains(3) && player1.contains(6) && player1.contains(9)){
            winer=1
        }
        if(player2.contains(3) && player2.contains(6) && player2.contains(9)){
            winer=2
        }


        if( winer != -1){

            if (winer==1){
                android.widget.Toast.makeText(this," Player 1  win the game", android.widget.Toast.LENGTH_LONG).show()
            }else{
                android.widget.Toast.makeText(this," Player 2  win the game", android.widget.Toast.LENGTH_LONG).show()

            }

        }

    }


    fun AutoPlay(cellID:Int){



        var buSelect:Button?
        when(cellID){
            1-> buSelect=bu1
            2-> buSelect=bu2
            3-> buSelect=bu3
            4-> buSelect=bu4
            5-> buSelect=bu5
            6-> buSelect=bu6
            7-> buSelect=bu7
            8-> buSelect=bu8
            9-> buSelect=bu9
            else->{
                buSelect=bu1
            }
        }

        PlayGame(cellID,buSelect)

    }



    protected fun buRequestEvent(view:android.view.View){
        var userDemail=etEmail!!.text.toString()
        var database = FirebaseDatabase.getInstance()
        var myRef = database?.reference
        myRef.child("Users").child(SplitString(userDemail)).child("Request").push().setValue(myEmail)


        PlayerOnline(SplitString(myEmail!!)+ SplitString(userDemail)) // husseinjena
        PlayerSymbol="X"
    }

    protected fun buAcceptEvent(view:android.view.View){
        var database = FirebaseDatabase.getInstance()
        var myRef = database?.reference
        var userDemail=etEmail!!.text.toString()//push will create another node with random id
        myRef.child("Users").child( SplitString(userDemail)).child("Request").push().setValue(myEmail)


        PlayerOnline(SplitString(userDemail)+SplitString(myEmail!!)) //husseinjena
        PlayerSymbol="O"

    }

    var sessionID:String?=null
    var PlayerSymbol:String?=null
    fun PlayerOnline(sessionID:String){
        this.sessionID=sessionID
        var database = FirebaseDatabase.getInstance()
        var myRef = database?.reference
        myRef.child("PlayerOnline").removeValue()
        myRef.child("PlayerOnline").child(sessionID)
            .addValueEventListener(object:ValueEventListener{
                override fun onDataChange(dataSnapshot: DataSnapshot) {
                    try{
                        player1.clear()
                        player2.clear()
                        val td=dataSnapshot!!.value as HashMap<String,Any>
                        if(td!=null){

                            var value:String
                            for (key in td.keys){
                                value= td[key] as String

                                if(value!= myEmail){
                                    ActivePlayer= if(PlayerSymbol==="X") 1 else 2
                                }else{
                                    ActivePlayer= if(PlayerSymbol==="X") 2 else 1
                                }

                                AutoPlay(key.toInt())


                            }

                        }

                    }catch (ex:Exception){}
                }

                override fun onCancelled(p0: DatabaseError) {

                }

            })

    }



    var number=0
    fun IncommingCalls(){
        var database = FirebaseDatabase.getInstance()
        var myRef = database?.reference
        myRef.child("Users").child(SplitString(myEmail!!)).child("Request")
            .addValueEventListener(object:ValueEventListener{

                override fun onDataChange(dataSnapshot: DataSnapshot) {



                    try{
                        val td=dataSnapshot!!.value as HashMap<String,Any>
                        if(td!=null){

                            var value:String
                            for (key in td.keys){
                                value= td[key] as String
                                etEmail.setText(value)

                                val notifyme=Notifications()
                                notifyme.Notify(applicationContext,value + "want to play tic tac toe",number)
                                number++
                                myRef.child("Users").child(SplitString(myEmail!!)).child("Request").setValue(true)

                                break

                            }

                        }

                    }catch (ex:Exception){}
                }

                override fun onCancelled(p0: DatabaseError) {

                }

            })
    }


    fun  SplitString(str:String):String{
        var split=str.split("@")
        return split[0]
    }
}

Ошибка, которую я получаю на logcat

2022-01-19 12:45:03.601 30370-30370/com.example.tictactoe E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.tictactoe, PID: 30370
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.tictactoe/com.example.tictactoe.RoomActivity}: java.lang.IllegalArgumentException: Given String is empty or null
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3616)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3780)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2251)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:233)
        at android.app.ActivityThread.main(ActivityThread.java:8068)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:631)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:978)
     Caused by: java.lang.IllegalArgumentException: Given String is empty or null
        at com.google.android.gms.common.internal.Preconditions.checkNotEmpty(com.google.android.gms:play-services-basement@@18.0.0:2)
        at com.google.firebase.auth.FirebaseAuth.createUserWithEmailAndPassword(com.google.firebase:firebase-auth@@21.0.1:1)
        at com.example.tictactoe.RoomActivity.LoginToFirebase(RoomActivity.kt:33)
        at com.example.tictactoe.RoomActivity.buLoginEvent(RoomActivity.kt:23)
        at com.example.tictactoe.RoomActivity.onCreate(RoomActivity.kt:19)
        at android.app.Activity.performCreate(Activity.java:8006)
        at android.app.Activity.performCreate(Activity.java:7990)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1329)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3589)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3780) 
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85) 
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) 
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2251) 
        at android.os.Handler.dispatchMessage(Handler.java:106) 
        at android.os.Looper.loop(Looper.java:233) 
        at android.app.ActivityThread.main(ActivityThread.java:8068) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:631) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:978) 
0
Divyanshu Dobriyal 19 Янв 2022 в 11:15
Если у вас возникнут проблемы, лучше всего создать MCVE при публикации вопроса. Вы опубликовали почти 500 (пятьсот) строк кода для решения этой проблемы. Людям сложно разбирать и отлаживать онлайн. Пожалуйста, отредактируйте свой вопрос и изолируйте проблему, так вы увеличите свои шансы на помощь.
 – 
Alex Mamo
19 Янв 2022 в 11:16

3 ответа

Как вы можете видеть в журналах, ваш адрес электронной почты или пароль недействителен или пуст, когда вы звоните createUserWithEmailAndPassword.

Просмотрите журналы и попробуйте отладить свой код, чтобы увидеть, не являются ли значения для электронной почты и пароля нулевыми или пустыми.

Caused by: java.lang.IllegalArgumentException: Given String is empty or null
    at com.google.android.gms.common.internal.Preconditions.checkNotEmpty(com.google.android.gms:play-services-basement@@18.0.0:2)
    at com.google.firebase.auth.FirebaseAuth.createUserWithEmailAndPassword(com.google.firebase:firebase-auth@@21.0.1:1)
0
Maksim Novikov 19 Янв 2022 в 11:27

Когда я получаю вашу трассировку стека, вы передаете пустые строки в метод createUserWithEmailAndPassword. Вроде не позволяет.

Рекомендую добавить проверки в метод buLoginEvent:

fun buLoginEvent(){
   val emailString = email.text.toString()
   val passwordString = password.text.toString()
   if(emailString.isNotEmpty() && passwordString.isNotEmpty()) {
       LoginToFirebase(emailString, passwordString);
   } else {
       //show error message to user
   }
}
0
Ircover 19 Янв 2022 в 11:29
  • mAuth!!.createUserWithEmailAndPassword(email,password) возможно, ваш адрес электронной почты или пароль недействительны.
Caused by: java.lang.IllegalArgumentException: Given String is empty or null
       at com.google.android.gms.common.internal.Preconditions.checkNotEmpty(com.google.android.gms:play-services-basement@@18.0.0:2)
       at com.google.firebase.auth.FirebaseAuth.createUserWithEmailAndPassword(com.google.firebase:firebase-auth@@21.0.1:1)
0
Nimantha 19 Янв 2022 в 11:30