Android.net.rtp - AudioStream.join() - java.lang.NullPointerException

363 views Asked by At

I got a java.lang.NullPointerException and I cannot solve the problem.

I have to do a simple VoIP Trasmission using Android.net.rtp.

I wrote the following code:

private static final AudioCodec myAudioCodec_COSTANTE = AudioCodec.PCMU ; 
private static final int myAudioGroupTX_COSTANTE = AudioGroup.MODE_NORMAL ; 
private static final int myAudioGroupRX_COSTANTE = AudioGroup.MODE_NORMAL ;
private static final int myRtpStreamTX_COSTANTE = RtpStream.MODE_SEND_ONLY ;
private static final int myRtpStreamRX_COSTANTE = RtpStream.MODE_RECEIVE_ONLY ; 
private static final int myAudioManagerTX_COSTANTE = AudioManager.MODE_IN_COMMUNICATION;
private static final int myAudioManagerRX_COSTANTE = AudioManager.MODE_IN_COMMUNICATION; 


myAudioStream = new AudioStream(localClientIP);
myAudioGroup = new AudioGroup();
myAudioGroup.setMode(myAudioGroupTX_COSTANTE);
myAudioStream.join(null); 
myAudioStream.setCodec(myAudioCodec_COSTANTE);
myAudioStream.setMode(myRtpStreamTX_COSTANTE);

Log.w(tag, "FAU dentro startGroupVoIP_TX(); myAudioGroup: " + myAudioGroup);  //My Debug
Log.w(tag, "FAU dentro startGroupVoIP_TX(); myAudioStream: " + myAudioStream);  //My Debug

myAudioStream.join(myAudioGroup); //Row 124

I got the following error (android studio logcat):

06-16 14:58:52.855    6690-6726/com.fpricoco.iptetraclient W/Voip_Manager﹕ FAU dentro startGroupVoIP_TX(); myAudioGroup: android.net.rtp.AudioGroup@4240d718
06-16 14:58:52.855    6690-6726/com.fpricoco.iptetraclient W/Voip_Manager﹕ FAU dentro startGroupVoIP_TX(); myAudioStream: android.net.rtp.AudioStream@4240d3f0
06-16 14:58:52.865    6690-6726/com.fpricoco.iptetraclient D/Voip_Manager﹕ Eccezione sul try del nuovo Thread di startGroupVoIP_TX(); exception: java.lang.NullPointerException
    java.lang.IllegalStateException: java.lang.NullPointerException
            at android.net.rtp.AudioGroup.add(AudioGroup.java:156)
            at android.net.rtp.AudioStream.join(AudioStream.java:97)
            at com.fpricoco.iptetraclient.VoIP.Voip_Manager$1.run(Voip_Manager.java:124)
            at java.lang.Thread.run(Thread.java:856)
     Caused by: java.lang.NullPointerException
            at android.net.rtp.AudioGroup.add(AudioGroup.java:149)
            at android.net.rtp.AudioStream.join(AudioStream.java:97)
            at com.fpricoco.iptetraclient.VoIP.Voip_Manager$1.run(Voip_Manager.java:124)
            at java.lang.Thread.run(Thread.java:856)

As you can see, I got the error in the last row of the code (row 124). Moreover in the first 2 rows of logcat you can see that my debug shows that the 2 objects "myAudioGroup" and "myAudioStream" are not NULL. Can anybody help? I'm working on that error from a couple of days without any success... Thank you in advance Fausto

1

There are 1 answers

1
Priyank Patel On BEST ANSWER

First you have to call myAudioStream.associate (InetAddress remoteAddress, int remotePort) before calling myAudioStream.join(myAudioGroup);