Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attempt to invoke virtual method 'io.agora.chat.adapter.EMAChatManager io.agora.chat.adapter.EMAChatClient.getChatManager()' on a null object reference #30

Open
VishalShahSamcom opened this issue Aug 30, 2024 · 1 comment

Comments

@VishalShahSamcom
Copy link

I am trying to create the same application in android but using kotlin. I tried the steps mentioned in the ReadMe file but the steps for activity adding and initiating the EaseCallKit is extremely difficult and confusing to implement those. Still somehow I tried to manage to initiate it.

Adding my "MainAcitivty.kt" File and please correct me if I am wrong, I have created another activity named as "CallSingleBaseActivity" which inherits "EaseCallSingleBaseActivity" as mentioned in the steps.

image

Just like this.

MainActivity.kt code

 `
  class MainActivity : AppCompatActivity() {
private val callKitListener: EaseCallKitListener = object : EaseCallKitListener {
    override fun onInviteUsers(
        callType: EaseCallType?, existMembers: Array<out String>?, ext: JSONObject?
    ) {
        Log.d("onInviteUsers", "${callType?.name}\n $existMembers \n $ext")
    }

    override fun onEndCallWithReason(
        callType: EaseCallType?,
        channelName: String?,
        reason: EaseCallEndReason?,
        callTime: Long
    ) {
        Log.d(
            "onEndCallWithReason",
            "${callType?.name}\n $channelName \n ${reason?.name} \n $callTime"
        )
    }

    override fun onReceivedCall(
        callType: EaseCallType?, fromUserId: String?, ext: JSONObject?
    ) {
        Log.d("onReceivedCall", "${callType?.name}\n $fromUserId \n $ext")
    }

    override fun onCallError(type: EaseCallError?, errorCode: Int, description: String?) {
        Log.d("onCallError", "${type?.name}\n $errorCode \n $description")
    }

    override fun onInViteCallMessageSent() {
        Log.d("onInViteCallMessageSent", "Invite Call Sent")
    }

    override fun onRemoteUserJoinChannel(
        channelName: String?,
        userName: String?,
        uid: Int,
        callback: EaseCallGetUserAccountCallback?
    ) {
        Log.d("onRemoteUserJoinChannel", "${channelName}\n $userName \n $uid \n $callback")
    }

}
private lateinit var callKit: EaseCallKit
private lateinit var binding: ActivityMainBinding
override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    enableEdgeToEdge()
    binding = ActivityMainBinding.inflate(layoutInflater)
    setContentView(binding.root)
    ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
        val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
        v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
        insets
    }
    val appId = "8041ae7edbde4f4ab8fedd1a45cd6f39"
    val appCertificate = "YOUR_APP_CERTIFICATE"
    val userId = "USER_ID"
    val expireTimeInSeconds = 3600L // 1 hour
    //        val userManager = ContextCompat.getSystemService(this, UserHandle::class.java) as UserHandle
    val employeeUserId = "66cf03577aa063120cc7fb3b"
    val employerUserId = "66cf05677aa063120cc803d7"
    callKit = EaseCallKit.getInstance()
    // Construct the CallKitConfig class.
    val callKitConfig = EaseCallKitConfig()
    // Set the call out time (ms).
    callKitConfig.callTimeOut = 30 * 1000
    // Set the Agora App ID.
    callKitConfig.agoraAppId = appId
    callKitConfig.isEnableRTCToken = true
    val ringFile: String = EaseCallFileUtils.getModelFilePath(this, "huahai.mp3")
    callKitConfig.ringFile = ringFile
    val userInfoMap: HashMap<String, EaseCallUserInfo> = HashMap()
    userInfoMap[employeeUserId] = EaseCallUserInfo("Employee", null)
    userInfoMap[employerUserId] = EaseCallUserInfo("Employer", null)
    callKitConfig.userInfoMap = userInfoMap

    callKit.init(this, callKitConfig)
    callKit.registerVideoCallClass(CallSingleBaseActivity::class.java)
    callKit.setCallKitListener(callKitListener)
    binding.btnJoin.setOnClickListener {
        callKit.startSingleCall(EaseCallType.CONFERENCE_VIDEO_CALL, employeeUserId, null)
    }
}

/*fun generateRtmToken(
    appId: String, appCertificate: String, userId: String, expireTimeInSeconds: Long
): String {
    val tokenBuilder = RtmTokenBuilder2()
    val currentTimestamp = (System.currentTimeMillis() / 1000).toInt()
    val expirationTimestamp = currentTimestamp + expireTimeInSeconds

    return tokenBuilder.buildToken(
        appId, appCertificate, userId, RtmTokenBuilder2.Role.Rtm_User, expirationTimestamp
    )
}*/
}

`

Here as soon as I run the application, it gets crashed and this error pops up.

Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'io.agora.chat.adapter.EMAChatManager io.agora.chat.adapter.EMAChatClient.getChatManager()' on a null object reference
at io.agora.chat.ChatClient.chatManager(Unknown Source:15)
at io.agora.chat.callkit.EaseCallKit.removeMessageListener(EaseCallKit.java:875)
at io.agora.chat.callkit.EaseCallKit.init(EaseCallKit.java:146)
at com.vishal.agoracallkit.MainActivity.onCreate(MainActivity.kt:101)
at android.app.Activity.performCreate(Activity.java:8129)
at android.app.Activity.performCreate(Activity.java:8109)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1344)

Can anyone help me out with this?

Also, if possible can anyone add any library or solution on how to use this library for achieving 1 to 1 video calls and also sending and receive Incoming call Dialers and rest of that.

@xuchengpu
Copy link
Contributor

xuchengpu commented Sep 5, 2024

the Chat SDK should be initialized before you call EaseCallKit.init() . It is already mentioned in the initialization steps of the readme file

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants