模拟器上的Sip错误

时间:2016-01-06 05:15:16

标签: android eclipse android-emulator asterisk sip

嗨,实际上我正在尝试创建一个与Sip和Asterisk通信一起工作的应用程序,但是当我试图在我的设备上运行此应用程序时,它的工作正常,但是如果它尝试使用Android模拟器那么请向我显示错误请帮助我来解决这个错误

    public class MainActivity extends Activity {
    public SipProfile me = null;
    public SipProfile.Builder builder = null;
    public SipManager mSipManager = null;
    public String sipaddress = null;
    public String username = "17772146242101";
    public String domain = "callcentric.com";
    public String password = "Gjmurugan2!";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Button b1 = (Button) findViewById(R.id.button1);
        if (mSipManager == null) {
            mSipManager = SipManager.newInstance(getApplicationContext());
        }

    }
        public void Register(View v)
        {
            try {
                builder = new SipProfile.Builder(username, domain);
                builder.setPassword(password);
                me = builder.build();
            } catch (ParseException e) {

                e.printStackTrace();
            }
              Intent intent=new Intent();
                intent.setAction("android.sipexample.INCOMING_CALL");
                PendingIntent pi=PendingIntent.getBroadcast(getApplicationContext(), 0, intent, Intent.FILL_IN_DATA);
                try {
                    mSipManager.open(me, pi, null);
                } catch (SipException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }

            try {
                mSipManager.setRegistrationListener(me.getUriString(), new SipRegistrationListener() {

                    public void onRegistering(String arg0) {
                        Log.d("Success", "Registering with SIP Server...");
                    }

                    public void onRegistrationDone(String arg0, long arg1) {
                        Log.d("Connection Ready", "Ready For Communication");
                    }

                    public void onRegistrationFailed(String arg0, int arg2, String arg1) {
                        Log.d("Error Code", Integer.toString(arg2));
                        Log.d("Error Message", arg1);
                    }
                });
            } catch (SipException e) {
                // TODO: handle exception
                e.printStackTrace();

            }
        }
        // closeLocalProfile();

    private void closeLocalProfile() {
        // TODO Auto-generated method stub
        if (mSipManager == null) {
            return;
        }
        try {
            if (me != null) {
                mSipManager.close(me.getUriString());
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}


<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.sipreg.MainActivity" >

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/hello_world" />

<Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/textView1"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="147dp"
    android:onClick="Register"
    android:text="Register-Sip" />

</RelativeLayout>

这是我在Logcat中的错误

01-05 23:58:43.997: D/AndroidRuntime(1069): Shutting down VM
01-05 23:58:43.997: W/dalvikvm(1069): threadid=1: thread exiting with    uncaught exception (group=0xb4a27ba8)
01-05 23:58:44.017: E/AndroidRuntime(1069): FATAL EXCEPTION: main
01-05 23:58:44.017: E/AndroidRuntime(1069): Process: com.example.sipreg,   PID: 1069
01-05 23:58:44.017: E/AndroidRuntime(1069): java.lang.IllegalStateException:  Could not execute method of the activity
01-05 23:58:44.017: E/AndroidRuntime(1069):     at android.view.View$1.onClick(View.java:3823)
01-05 23:58:44.017: E/AndroidRuntime(1069):     at android.view.View.performClick(View.java:4438)
01-05 23:58:44.017: E/AndroidRuntime(1069):     at android.view.View$PerformClick.run(View.java:18422)
01-05 23:58:44.017: E/AndroidRuntime(1069):     at android.os.Handler.handleCallback(Handler.java:733)
01-05 23:58:44.017: E/AndroidRuntime(1069):     at android.os.Handler.dispatchMessage(Handler.java:95)
01-05 23:58:44.017: E/AndroidRuntime(1069):     at android.os.Looper.loop(Looper.java:136)
01-05 23:58:44.017: E/AndroidRuntime(1069):     at android.app.ActivityThread.main(ActivityThread.java:5001)
01-05 23:58:44.017: E/AndroidRuntime(1069):     at java.lang.reflect.Method.invokeNative(Native Method)
01-05 23:58:44.017: E/AndroidRuntime(1069):     at java.lang.reflect.Method.invoke(Method.java:515)
01-05 23:58:44.017: E/AndroidRuntime(1069):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
01-05 23:58:44.017: E/AndroidRuntime(1069):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
01-05 23:58:44.017: E/AndroidRuntime(1069):     at dalvik.system.NativeStart.main(Native Method)
01-05 23:58:44.017: E/AndroidRuntime(1069): Caused by: java.lang.reflect.InvocationTargetException
01-05 23:58:44.017: E/AndroidRuntime(1069):     at java.lang.reflect.Method.invokeNative(Native Method)
01-05 23:58:44.017: E/AndroidRuntime(1069):     at java.lang.reflect.Method.invoke(Method.java:515)
01-05 23:58:44.017: E/AndroidRuntime(1069):     at android.view.View$1.onClick(View.java:3818)
01-05 23:58:44.017: E/AndroidRuntime(1069):     ... 11 more
01-05 23:58:44.017: E/AndroidRuntime(1069): Caused by: java.lang.NullPointerException
01-05 23:58:44.017: E/AndroidRuntime(1069):     at com.example.sipreg.MainActivity.Register(MainActivity.java:52)
01-05 23:58:44.017: E/AndroidRuntime(1069):     ... 14 more
01-05 23:58:45.777: I/Process(1069): Sending signal. PID: 1069 SIG: 9

1 个答案:

答案 0 :(得分:0)

有些仿真器不支持SIP,即使支持API也是如此。

因此,SipManager.newInstance可能会返回null:首先检查它!

旁注:如果我们清楚地知道您的MainActivity.java文件中的第52行,那将会有所帮助!