Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android SIP stack: NullPointerException on register

Tags:

android

sip

I've been writing code on a HTC Desire Z running 2.3.3 and it works fine - now I've come to test it on another device (Nexus One running 2.3.4), and it crashes. Here's the code:

if (me == null || sipManager == null || listener == null){
    Log.e("OH","NO");
}

sipManager.register(me, 30, listener);

None of the things I pass to sipManager.register are null (the log is never called), but here's my stack trace:

FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to create service com.myapp.Service: java.lang.NullPointerException
    at android.app.ActivityThread.handleCreateService(ActivityThread.java:1955)
    at android.app.ActivityThread.access$2500(ActivityThread.java:117)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:985)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:130)
    at android.app.ActivityThread.main(ActivityThread.java:3683)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:507)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
    at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
    at android.net.sip.SipManager.register(SipManager.java:474)
    at com.myapp.Service.onCreate(Service.java:159)
    at android.app.ActivityThread.handleCreateService(ActivityThread.java:1945)
    ... 10 more

Looking at the Android source doesn't seem to reveal anything obvious either - everything I'm passing to it is valid on another device.

Both devices are running 2.3+ and both have the SIP stack enabled:

if (SipManager.isVoipSupported(this) && SipManager.isApiSupported(this)){

EDIT:

Here's a full activity which replicates the issue:

public class SIPTest extends Activity {

    public SipManager sipManager = null;
    SipProfile me = null;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);


        if (SipManager.isVoipSupported(this) && SipManager.isApiSupported(this)){
            // SIP is supported, let's go!
            Log.e("SIP", "SUPPORTED");
            sipManager = SipManager.newInstance(this);


            String username = "username";
            String password = "password";
            String domain = "example.org";

            try {
                SipProfile.Builder builder = new SipProfile.Builder(username, domain);
                builder.setPassword(password);
                builder.setDisplayName(username);
                builder.setProfileName(username + "@" + domain);
                me = builder.build();

                sipManager.register(me, 30, new SipRegistrationListener() {
                        public void onRegistering(String localProfileUri) {
                            Log.e("SIP","Registering with SIP Server...");
                        }

                        public void onRegistrationDone(String localProfileUri, long expiryTime) {
                            Log.e("SIP","Ready!");
                        }

                        public void onRegistrationFailed(String localProfileUri, int errorCode,
                                String errorMessage) {
                            Log.e("SIP","Registration failed. " + errorMessage + " ("+errorCode+") - " + localProfileUri);
                        }
                    });
            } catch (ParseException pe) {
                Log.e("SIP","Connection Error.");
            } catch (SipException se) {
                Log.e("SIP","Connection error.");
            }

        }

    }
}
like image 535
simonmaddox Avatar asked Aug 12 '11 14:08

simonmaddox


1 Answers

You shall just place sipManager.open(me); before sipManager.register() is executed as new sip session needs to be created.

take care!

like image 50
Alex Avatar answered Oct 12 '22 08:10

Alex