E / Android运行时:致命异常:主进程:PID:2551

时间:2018-12-13 12:08:29

标签: java android android-studio webrtc

我在针对WebRTC的android项目中出错。

  

E / Android运行时:致命异常:主要       流程:com.audiocodes.mv.webrtcclient,PID:2551       java.lang.RuntimeException:无法启动活动ComponentInfo {com.audiocodes.mv.webrtcclient / com.audiocodes.mv.webrtcclient.Activities.SplashActivity}:java.lang.NullPointerException:尝试调用虚拟方法'java.util.ArrayList com.audiocodes.mv.webrtcsdk.useragent.AudioCodesUA.getSessionList()在空对象引用上           在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325)           在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)           在android.app.ActivityThread.access $ 800(ActivityThread.java:151)           在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1303)           在android.os.Handler.dispatchMessage(Handler.java:102)           在android.os.Looper.loop(Looper.java:135)           在android.app.ActivityThread.main(ActivityThread.java:5254)           在java.lang.reflect.Method.invoke(本机方法)           在java.lang.reflect.Method.invoke(Method.java:372)           在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:903)           在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)        原因:java.lang.NullPointerException:尝试在空对象引用上调用虚拟方法'java.util.ArrayList com.audiocodes.mv.webrtcsdk.useragent.AudioCodesUA.getSessionList()'           在com.audiocodes.mv.webrtcclient.General.ACManager.getActiveSession(ACManager.java:139)           在com.audiocodes.mv.webrtcclient.General.ACManager.isAllredyInActiveCall(ACManager.java:160)           在com.audiocodes.mv.webrtcclient.General.NotificationUtils.createAppNotification(NotificationUtils.java:33)           在com.audiocodes.mv.webrtcclient.Activities.BaseAppCompatActivity.onCreate(BaseAppCompatActivity.java:34)           在com.audiocodes.mv.webrtcclient.Activities.SplashActivity.onCreate(SplashActivity.java:29)           在android.app.Activity.performCreate(Activity.java:5990)           在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)           在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)

我认为错误在这里。但是我不知道。这是代码。

public class ACManager implements AudioCodesEventListener {

private static final String TAG = "ACManager";

private static ACManager instance;
private boolean registerState;

public static synchronized ACManager getInstance() {
    if (instance == null) {
        instance = new ACManager();
    }
    return instance;
}

public void startLogin(){
    Log.d(TAG, "startLogin");
    boolean loginit=false;
    try {
        initACUA();
        loginit = true;
    } catch (Exception e) {
        Log.d(TAG, "can't set log level");
    }
    initWebRTC(Prefs.getSipAccount());

    try {
        AudioCodesUA.getInstance().login(MainApp.getGlobalContext().getApplicationContext());
        if(!loginit) {
            initACUA();
        }
    } catch (Exception e) {
        Log.d(TAG, "Error in login: "+e);
        Toast.makeText(MainApp.getGlobalContext(), "Error in login", Toast.LENGTH_SHORT).show();
    }
}
public void initACUA(){
    AudioCodesUA.getInstance().setLogger(new LogI());
    AudioCodesUA.getInstance().setLogLevel(LogLevel.VERBOSE);
}

public void startLogout(){
    Log.d(TAG, "startLogout");
    try {
        AudioCodesUA.getInstance().logout();
    } catch (Exception e) {
        Log.d(TAG, "Error in logout");
    }
}

public void initWebRTC(SipAccount sipAccount) {
    String proxy=sipAccount.getProxy();
    int port = sipAccount.getPort();
    String domain = sipAccount.getDomain();
    Transport transport = sipAccount.getTransport();
    String username = sipAccount.getUsername();
    String password = sipAccount.getPassword();
    String displayName =  sipAccount.getDisplayName();

    Log.d(TAG,"sipAccount: "+sipAccount.toString());


    AudioCodesUA.getInstance().setServerConfig(proxy,port,domain,transport,new ArrayList<PeerConnection.IceServer>());

    AudioCodesUA.getInstance().setAccount(username,password,displayName);

    AudioCodesUA.getInstance().setListener(this);

    updateWebRTCConfig();

}

public void updateWebRTCConfig()
{
    DTMFOptions.DTMFMethod dtmfMethod = Prefs.getDTMFType();
    DTMFOptions dtmfOptions = new DTMFOptions();
    dtmfOptions.dtmfMethod = dtmfMethod;
    Log.d(TAG,"use dtmfMethod: "+dtmfMethod);
    ACConfiguration.getConfiguration().setDtmfOptions(dtmfOptions);

    Log.d(TAG,"use isAutoRedirect: "+Prefs.isAutoRedirect());
    ACConfiguration.getConfiguration().setAutomaticCallOnRedirect(Prefs.isAutoRedirect());
    RemoteContact remoteContact = new RemoteContact();
    remoteContact.setScheme(null);
    remoteContact.setDisplayName(Prefs.getRedirectCallUser());
    remoteContact.setUserName(Prefs.getRedirectCallUser());
    remoteContact.setDomain(Prefs.getSipAccount().getDomain());

    Log.d(TAG,"use isRedirectCall: "+Prefs.isRedirectCall()+" with RedirectCallUser: "+Prefs.getRedirectCallUser());
    ACConfiguration.getConfiguration().setRedirect(Prefs.isRedirectCall(), remoteContact);
}


@Override
public void loginStateChanged(boolean isLogin, String cause) {
    Log.d(TAG,"loginStateChanged isLogin: "+isLogin+" cause: "+cause);
    Log.d(TAG,"loginStateChanged currentState: "+ isLogin+" prevState: "+registerState);
    if(registerState != isLogin) {
        registerState = isLogin;
        CallBackHandler.loginStateChange(registerState);
        NotificationUtils.createAppNotification();

    }
}

public AudioCodesSession getActiveSession()
{
    AudioCodesSession audioCodesSession=null;
    ArrayList<AudioCodesSession> audioCodesSessionArrayList = AudioCodesUA.getInstance().getSessionList();
    for (AudioCodesSession session: audioCodesSessionArrayList) {
        if (session.getCallState()!=null)
        {
            audioCodesSession = session;
            break;
        }
    }

    return audioCodesSession;
}

public ArrayList<AudioCodesSession> getSessionList()
{
    return AudioCodesUA.getInstance().getSessionList();
}

public boolean isAllredyInActiveCall()
{
    return getActiveSession()!=null && getActiveSession().getCallState()!= CallState.NULL;

}

public void callNumber(String callNumber)
{
    callNumber(callNumber, false);
}
public void callNumber(String callNumber, boolean videoCall)
{
    try {
        Log.d(TAG, "start callNumber: " +callNumber+ " isVideoCall: "+videoCall);
        RemoteContact contact= new RemoteContact();
        contact.setUserName(callNumber);
        contact.setDisplayName(callNumber);
        AudioCodesSession session = AudioCodesUA.getInstance().call(contact,videoCall, null );
        Intent callIntent = new Intent(MainApp.getGlobalContext(), CallActivity.class);

        session.addSessionEventListener(audioCodesSessionEventListener);

        Log.d(TAG, "callNumber startActivity" );
        callIntent.putExtra(CallActivity.SESSION_ID, session.getSessionID() );
        callIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        MainApp.getGlobalContext().startActivity(callIntent);
    } catch (WebRTCException e) {
        Log.d(TAG, "oops: " + e.getMessage());
    }
}

@Override
public void incomingCall(AudioCodesSession call) {
    Log.d(TAG, "Incoming call");
    Log.d(TAG, "Remote user: " + call.getRemoteNumber());
    Intent incomingCallIntent = new Intent(MainApp.getGlobalContext(), IncomingCallActivity.class);
    incomingCallIntent.putExtra(IncomingCallActivity.SESSION_ID, call.getSessionID());
    call.addSessionEventListener(audioCodesSessionEventListener);

    MainApp.getGlobalContext().startActivity(incomingCallIntent);
}

public boolean isRegisterState() {
    return registerState;
}

AudioCodesSessionEventListener audioCodesSessionEventListener = new AudioCodesSessionEventListener() {
    @Override
    public void callTerminated(AudioCodesSession session) {

        Log.d(TAG, "callTerminated name: "+session.getRemoteNumber().getDisplayName()+" userName: "+session.getRemoteNumber().getUserName());

        saveCallHistory(session);

        ACCallStatistics acCallStatistics = session.getStats();
        Prefs.setCallStats(acCallStatistics);
        Log.d(TAG, "ACCallStatistics: "+acCallStatistics);


    }

    private void saveCallHistory(AudioCodesSession session)
    {
        CallEntry callEntry = new CallEntry();
        callEntry.setContactName(session.getRemoteNumber().getDisplayName());
        callEntry.setContactNumber(session.getRemoteNumber().getUserName());

        long callStartTime = session.getCallStartTime();
        if(callStartTime==0) {
            callStartTime= new Date().getTime();
        }
        callEntry.setStartTime(callStartTime);

        long callDuration = session.duration();
        if(callDuration>0) {
            callDuration = callDuration*1000;
        }

        CallEntry.CallType callType = CallEntry.CallType.OUTGOING;
        if(!session.isOutgoing())
        {
            if(callDuration>0) {
                callType = CallEntry.CallType.INCOMING;
            }
            else
            {
                callType = CallEntry.CallType.MISSED;
            }
        }
        callEntry.setCallType(callType);

        callEntry.setDuration( callDuration);
        MainApp.getDataBase().addEntry(callEntry);
    }

    @Override
    public void callProgress(AudioCodesSession session) {
        Log.d(TAG, "callProgress name: "+session.getRemoteNumber().getDisplayName()+" userName: "+session.getRemoteNumber().getUserName());
    }

    @Override
    public void cameraSwitched(boolean frontCamera) {
        Log.d(TAG, "cameraSwitched isfrontCamera: "+frontCamera);

    }

    @Override
    public void reinviteWithVideoCallback(AudioCodesSession audioCodesSession) {
        Log.d(TAG, "reinviteWithVideoCallback name: "+audioCodesSession.getRemoteNumber().getDisplayName()+" userName: "+audioCodesSession.getRemoteNumber().getUserName());
    }
};

0 个答案:

没有答案