我试图实现自己的android sip实现,但我在使用SIP服务器注册时遇到问题。具体来说,SipManager.register()函数抛出NullPointerException。以前有人经历过这个吗?以下功能中没有任何内容为空,所以我不明白这是从哪里来的。感谢
public boolean initializeProfile() {
final Globals global = Globals.getInstance();
if (sipProfile != null)
closeLocalProfile();
String username = "omitted";
String password = "omitted";
String server = "omitted";
try {
global.Log("Trying to build the profile");
SipProfile.Builder builder = new SipProfile.Builder(username,
server);
builder.setPassword(password);
sipProfile = builder.build();
builder.setAutoRegistration(true);
sipManager.open(sipProfile);
SipRegistrationListener listener = new SipRegistrationListener() {
public void onRegistering(String localProfileUri) {
global.Log("Sip Listener- Attempting to Register");
}
public void onRegistrationDone(String localProfileUri,
long expiryTime) {
global.Log("Sip Listener- Registration Success!");
}
public void onRegistrationFailed(String localProfileUri,
int errorCode, String errorMessage) {
global.Log("Sip Listener- Registration Failed");
}
};
sipManager.setRegistrationListener(sipProfile.getUriString(), listener);
//THIS IS WHERE THE EXCEPTION IS BEING THROWN
sipManager.register(sipProfile, 3000, listener);
if (sipManager.isRegistered(sipProfile.getUriString()))
{
global.Log("SipManager is ready for calls");
return true;
}
else
return false;
} catch (Exception ex) {
global.Log("---Error-- initializeProfile: " + ex.getMessage());
return false;
}
}
答案 0 :(得分:0)
解决了我自己的问题。似乎在线程中运行时这不能很好地工作。