它是一个app-to-app调用Android应用程序 早些时候我遇到了一些代码问题,也有一些例外,现在很好,但面临最后一个例外。 对于应用程序的调用活动,这是我的代码
public class CallActivity extends AppCompatActivity {
private com.sinch.android.rtc.calling.Call call;
private TextView callState;
private Button button;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.call);
TextView callState = (TextView) findViewById(R.id.callState);
Intent intent = getIntent();
String callerId = intent.getStringExtra("callerId");
final String recipientId = intent.getStringExtra("recipientId");
final SinchClient sinchClient = Sinch.getSinchClientBuilder()
.context(this)
.userId(""+callerId)
.applicationKey("c6a1ec06-3f48-4e2d-980c-021ea6d2c8ca")
.applicationSecret("pH2/AwzRJkmFS2M3kQ1XcA==")
.environmentHost("sandbox.sinch.com")
.build();
sinchClient.setSupportCalling(true);
sinchClient.startListeningOnActiveConnection();
sinchClient.start();
sinchClient.getCallClient().addCallClientListener(new SinchCallClientListener());
button = (Button) findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
call.addCallListener(new SinchCallListener());
if (call == null) {
call = sinchClient.getCallClient().callUser(recipientId);
button.setText("Hang Up");
} else {
call.hangup();
} // make a call!
}
});
}
private class SinchCallListener implements CallListener {
@Override
public void onCallProgressing(com.sinch.android.rtc.calling.Call progressingCall) {
callState.setText("ringing");
}
@Override
public void onCallEstablished(com.sinch.android.rtc.calling.Call establishedCall) {
callState.setText("connected");
setVolumeControlStream(AudioManager.STREAM_VOICE_CALL);
}
@Override
public void onCallEnded(com.sinch.android.rtc.calling.Call endedCall) {
callState.setText("");
call = null;
button.setText("Call");
setVolumeControlStream(AudioManager.USE_DEFAULT_STREAM_TYPE);
}
@Override
public void onShouldSendPushNotification(com.sinch.android.rtc.calling.Call call, List<PushPair>pushPairs) {
}
}
private class SinchCallClientListener implements com.sinch.android.rtc.calling.CallClientListener {
@Override
public void onIncomingCall(com.sinch.android.rtc.calling.CallClient callClient, com.sinch.android.rtc.calling.Call incomingCall) {
call = incomingCall;
call.answer();
call.addCallListener(new SinchCallListener());
button.setText("Hang Up");
}
}
}
logcat说:
03-24 20:45:49.789 25058-25058/com.example.abhinav123.sinch2 E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.abhinav123.sinch2, PID: 25058
Theme: themes:{}
java.lang.NullPointerException: Attempt to invoke interface method 'void com.sinch.android.rtc.calling.Call.addCallListener(com.sinch.android.rtc.calling.CallListener)' on a null object reference
at com.example.abhinav123.sinch2.CallActivity$1.onClick(CallActivity.java:49)
at android.view.View.performClick(View.java:5204)
at android.view.View$PerformClick.run(View.java:21158)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5461)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
第49行是:call.addCallListener(new SinchCallListener());
请帮助..
答案 0 :(得分:1)
您刚刚在此处声明call
:private com.sinch.android.rtc.calling.Call call;
但是在使用之前你还没有初始化它。