Android SIP堆栈:寄存器上的NullPointerException

时间:2011-08-12 14:10:54

标签: android sip

我一直在运行2.3.3的HTC Desire Z上编写代码并且工作正常 - 现在我来测试另一台设备(Nexus One运行2.3.4),它崩溃了。这是代码:

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

sipManager.register(me, 30, listener);

我传递给sipManager.register的所有内容都不为null(永远不会调用日志),但这是我的堆栈跟踪:

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

查看Android源代码似乎也没有显示任何明显的东西 - 我传递给它的所有内容在另一台设备上都有效。

两台设备都运行2.3+并且都启用了SIP堆栈:

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

编辑:

这是一个复制问题的完整活动:

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.");
            }

        }

    }
}

3 个答案:

答案 0 :(得分:4)

你应该放置sipManager.open(我);在执行sipManager.register()之前,需要创建新的sip会话。

小心!

答案 1 :(得分:1)

android代码中似乎有一个错误。

您可以从日志中看到Sipsession尝试调用OnRegisteredDone但由于空指针而失败

我注意到很多来自sipsession的空指针,这是导致sipmanager注册问题的原因

  

04-26 00:05:20.946:D / Dialapp(18910):ActivitySIPCallScreen:SipRegistrationListener \ onRegisteringDone sip:105@192.168.1.1
  04-26 00:05:20.946:D / Dialapp(18910):ActivitySIPCallScreen:updateStatus \ String \ Registered sip:105@192.168.1.1
  04-26 00:05:20.946:W / SipSession(1937):onRegistrationDone()
  04-26 00:05:20.946:W / SipSession(1937):java.lang.NullPointerException
  04-26 00:05:20.946:W / SipSession(1937):在android.os.Parcel.readException(Parcel.java:1328)
  04-26 00:05:20.946:W / SipSession(1937):在android.os.Parcel.readException(Parcel.java:1276)
  04-26 00:05:20.946:W / SipSession(1937):在android.net.sip.ISipSessionListener $ Stub $ Proxy.onRegistrationDone(ISipSessionListener.java:416)
  04-26 00:05:20.946:W / SipSession(1937):at com.android.server.sip.SipSessionListenerProxy $ 10.run(SipSessionListenerProxy.java:173)
  04-26 00:05:20.946:W / SipSession(1937):at java.lang.Thread.run(Thread.java:1027)

答案 2 :(得分:0)

在问题列表中报告了与nexus one和SIP相关的类似问题: http://code.google.com/p/android/issues/detail?id=17078&q=SIP%20register&colspec=ID%20Type%20Status%20Owner%20Summary%20Stars

我建议在此时单步调试以监视设置ISipSession的参数。由于系统配置,可能是其中一些设置不正确。

其他人要探索的代码

以下是其他人在查看问题时遇到的问题: http://www.google.com/codesearch#uX1GffpyOZk/voip/java/android/net/sip/SipManager.java&q=package:android.git%20SipManager.java&l=474