VoiSmart / pjsip-android

SIP Service for Android based on PJSIP
http://www.pjsip.org/
Apache License 2.0
288 stars 139 forks source link

Register account error NullPointException null string #36

Open robertstrz opened 6 years ago

robertstrz commented 6 years ago

Hello, I was trying to run the demo app but unfortunatelly I was unable to connect to my sip server. I have also tried with the data provided in demo app and I have also received the same NullPointException (it comes from the pjsip library also application does not crush)

  mSipAccount.setHost("192.168.1.154")
                .setPort(5060)
                .setTcpTransport(true)
                .setUsername("200")
                .setPassword("password200")
                .setRealm("devel.it");

04-20 14:50:42.682 12664-13179/net.gotev.sipservicedemo E/SipService: Error while adding sip:200@devel.it java.lang.NullPointerException: null string at org.pjsip.pjsua2.pjsua2JNI.AccountSipConfig_contactUriParams_set(Native Method) at org.pjsip.pjsua2.AccountSipConfig.setContactUriParams(AccountSipConfig.java:73) at net.gotev.sipservice.SipAccountData.getAccountConfig(SipAccountData.java:194) at net.gotev.sipservice.SipAccount.create(SipAccount.java:39) at net.gotev.sipservice.SipService.addAccount(SipService.java:892) at net.gotev.sipservice.SipService.handleSetAccount(SipService.java:624) at net.gotev.sipservice.SipService.access$700(SipService.java:86) at net.gotev.sipservice.SipService$2.run(SipService.java:147) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:148) at android.os.HandlerThread.run(HandlerThread.java:61)

noman720 commented 5 years ago

Hi @gotev, I am getting the same error when I am going to register a sip account. Please, can you give any hints to solve the issue?

jojupiter commented 5 years ago

I also have the same problem. you found the solution

aenonGit commented 5 years ago

which version? tried the latest?

jojupiter commented 5 years ago

this sip client works with asterisk pbx ? because my pbx is asterisk

jojupiter commented 5 years ago

which version? tried the latest? I use the latest version

jojupiter commented 5 years ago

which version? tried the latest?

here is my code

   public class fofe extends Activity {

         private int port= 5061;
 private  String realm="192.168.1.197";
 private  String name="300";
 private  String password="poseidon";
 private  String numberToCall="sip:301@192.168.1.197";

private static final String KEY_SIP_ACCOUNT = "sip_account";
private SipAccountData mSipAccount;

private BroadcastEventReceiver sipEvents = new BroadcastEventReceiver() {

    @Override
    public void onRegistration(String accountID, pjsip_status_code registrationStateCode) {
        if (registrationStateCode == pjsip_status_code.PJSIP_SC_OK) {
            Toast.makeText(fofe.this, "Registered", Toast.LENGTH_SHORT).show();
        } else {
            Toast.makeText(fofe.this, "Unregistered", Toast.LENGTH_SHORT).show();
        }
    }

    @Override
    public void onReceivedCodecPriorities(ArrayList<CodecPriority> codecPriorities) {
        for (CodecPriority codec : codecPriorities) {
            if (codec.getCodecName().startsWith("PCM")) {
                codec.setPriority(CodecPriority.PRIORITY_MAX);
            } else {
                codec.setPriority(CodecPriority.PRIORITY_DISABLED);
            }
        }
        SipServiceCommand.setCodecPriorities(fofe.this, codecPriorities);
    }
};

  @Override
   protected void onSaveInstanceState(Bundle outState) {
      if (mSipAccount != null) {
        outState.putParcelable(KEY_SIP_ACCOUNT, mSipAccount);
    }

    super.onSaveInstanceState(outState);
}

  @Override
   protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_fofe);

    Logger.setLogLevel(Logger.LogLevel.DEBUG);

    if (savedInstanceState != null && savedInstanceState.containsKey(KEY_SIP_ACCOUNT)) {
        mSipAccount = savedInstanceState.getParcelable(KEY_SIP_ACCOUNT);
    }

    onRegister();
}

@Override
protected void onPause() {
    super.onPause();
    sipEvents.unregister(this);
}

   @Override
   protected void onResume() {
      super.onResume();
      sipEvents.register(this);
      }
     public void onRegister() {
          mSipAccount = new SipAccountData();

         mSipAccount.setHost("192.168.1.197")
            .setPort(port)
            .setTcpTransport(true)
            .setUsername(name)
            .setPassword(password)
            .setRealm(realm);
        SipServiceCommand.setAccount(this, mSipAccount);
       SipServiceCommand.getCodecPriorities(this);
   }

public void onCall() {
    if (mSipAccount == null) {
        Toast.makeText(this, "Add an account and register it first", Toast.LENGTH_LONG).show();
        return;
    }

    String number = numberToCall;

    if (number.isEmpty()) {
        number = "301";
        //Toast.makeText(this, "Provide a number to call", Toast.LENGTH_SHORT).show();
        //return;
    }

    SipServiceCommand.makeCall(this, mSipAccount.getIdUri(), number);
}

public void onTerminate() {
    SipServiceCommand.hangUpActiveCalls(this, mSipAccount.getIdUri());
}

}

aenonGit commented 5 years ago

git it! you need to pur the contactUriParams in your account, unfortunately I haven't initializaed it as a default empty string, thus it fails. As a workaround you can call .setContactUriParams(""); on your sipAccount

jojupiter commented 5 years ago

like this ? mSipAccount.setHost("192.168.1.197") .setPort(port) .setTcpTransport(true) .setUsername(name) .setPassword(password) .setRealm(realm) .setContactUriParams("")

i did it, the problem is not solved here is my code : https://github.com/jojupiter/wiaCall

please help me

aenonGit commented 5 years ago

but the app was crashing at that point. Did you get a different error?

cjcj125125 commented 5 years ago

like this ? mSipAccount.setHost("192.168.1.197") .setPort(port) .setTcpTransport(true) .setUsername(name) .setPassword(password) .setRealm(realm) .setContactUriParams("")

i did it, the problem is not solved here is my code : https://github.com/jojupiter/wiaCall

please help me

like this ? mSipAccount.setHost("192.168.1.197") .setPort(port) .setTcpTransport(true) .setUsername(name) .setPassword(password) .setRealm(realm) .setContactUriParams("")

i did it, the problem is not solved here is my code : https://github.com/jojupiter/wiaCall

please help me

I have encountered similar problems. Have you solved your problem? Can you help me?

ashishsecrets commented 1 year ago

It's working for me. I use realm same as host. And call id is string not int in sipAccount i think