您好我正在尝试使用android api进行sip调用,代码如下。 setRegistration侦听器方法为我的sipprofile抛出一个nullpointer,但是配置文件打印正常,所以有点丢失为什么它抛出错误。我是一个非常新的android这是我的第一个项目,所以任何帮助都会非常感谢。
public void MakeACall(String a){
try {
String ad="calling "+a;//a is peer address
res1.setText(ad);//res1 is textview
//sp() is method to generate profile
String b=sp("name","getonsip.com","pass").getUriString();//local profile
res1.setText(b);
System.out.println(b);//prints the sip profile fine
SipProfile mSipProfile = sp("name","getonsip.com","pass");
SipManager mSipManager =SipManager.newInstance(MainActivity.this);
mSipManager.setRegistrationListener(b,//nullpointer error is thrown here<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
new SipRegistrationListener() {
public void onRegistering(String localProfileUri) {
res1.setText("Registering with SIP Server...");
}
public void onRegistrationDone(String localProfileUri, long expiryTime) {
res1.setText("Ready");
}
public void onRegistrationFailed(String localProfileUri, int errorCode,
String errorMessage) {
res1.setText("Registration failed. Please check settings.");
}
});
SipAudioCall.Listener whatWasThat = new SipAudioCall.Listener() {
@Override
public void onCallEstablished(SipAudioCall call) {
call.startAudio();
call.setSpeakerMode(true);
call.toggleMute();
res1.setText("calling");
}
@Override
public void onCallEnded(SipAudioCall call) {
res1.setText("ended");
}
};
mSipManager.makeAudioCall(sp("name","getonsip.com","pass").getUriString(),
sp("other","getonsip.com","pass").getUriString(), whatWasThat, 30);
} catch (java.text.ParseException e) {
System.out.println("error with profile string thing");
e.printStackTrace();
} catch (SipException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}//end makecall()
这里是logcat
03-29 15:05:20.679: D/AndroidRuntime(11466): Shutting down VM
03-29 15:05:20.679: W/dalvikvm(11466): threadid=1: thread exiting with uncaught exception (group=0x40018578)
03-29 15:05:20.679: E/AndroidRuntime(11466): FATAL EXCEPTION: main
03-29 15:05:20.679: E/AndroidRuntime(11466): java.lang.NullPointerException
03-29 15:05:20.679: E/AndroidRuntime(11466): at com.example.test2.MainActivity.MakeACall(MainActivity.java:51)
03-29 15:05:20.679: E/AndroidRuntime(11466): at com.example.test2.MainActivity$1.onClick(MainActivity.java:35)
03-29 15:05:20.679: E/AndroidRuntime(11466): at android.view.View.performClick(View.java:2485)
03-29 15:05:20.679: E/AndroidRuntime(11466): at android.view.View$PerformClick.run(View.java:9080)
03-29 15:05:20.679: E/AndroidRuntime(11466): at android.os.Handler.handleCallback(Handler.java:587)
03-29 15:05:20.679: E/AndroidRuntime(11466): at android.os.Handler.dispatchMessage(Handler.java:92)
03-29 15:05:20.679: E/AndroidRuntime(11466): at android.os.Looper.loop(Looper.java:123)
03-29 15:05:20.679: E/AndroidRuntime(11466): at android.app.ActivityThread.main(ActivityThread.java:3687)
03-29 15:05:20.679: E/AndroidRuntime(11466): at java.lang.reflect.Method.invokeNative(Native Method)
03-29 15:05:20.679: E/AndroidRuntime(11466): at java.lang.reflect.Method.invoke(Method.java:507)
03-29 15:05:20.679: E/AndroidRuntime(11466): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
03-29 15:05:20.679: E/AndroidRuntime(11466): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
03-29 15:05:20.679: E/AndroidRuntime(11466): at dalvik.system.NativeStart.main(Native Method)