0

I am trying to use sinch an i am having erros i dont know why an i seem to have set it well.

and it is pointing me to this part of the code which

public void that(final String name) {
    call.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View arg0) {
            if ((getSinchServiceInterface() == null) || (!getSinchServiceInterface().isStarted())) {
                getSinchServiceInterface().startClient(name);
            }
        }
    });
}

the "getSinchServiceInterface().startClient(name);"

this is my error

java.lang.NullPointerException: Attempt to invoke virtual method 'void com.obi.thinker.logins.call.SinchService$SinchServiceInterface.startClient(java.lang.String)' on a null object reference
                                                                                at com.obi.thinker.logins.tabs.Chatting$caller$1.onClick(Chatting.java:386)
                                                                                at android.view.View.performClick(View.java:5265)
                                                                                at android.view.View$PerformClick.run(View.java:21534)
                                                                                at android.os.Handler.handleCallback(Handler.java:815)
                                                                                at android.os.Handler.dispatchMessage(Handler.java:104)
                                                                                at android.os.Looper.loop(Looper.java:207)
                                                                                at android.app.ActivityThread.main(ActivityThread.java:5683)
                                                                                at java.lang.reflect.Method.invoke(Native Method)
                                                                                at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
                                                                                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679)

I dont understand

arinze
  • 439
  • 1
  • 6
  • 27

2 Answers2

1
if ((getSinchServiceInterface() != null && !getSinchServiceInterface().isStarted())) {
                getSinchServiceInterface().startClient(name);
            }

the callstack says:

getSinchServiceInterface() is null

And would suggest to read this: https://stackoverflow.com/a/41477703/1979882

Community
  • 1
  • 1
Vyacheslav
  • 26,359
  • 19
  • 112
  • 194
  • please i still dont understand the answer. Everything work when i create a separate java class . but i create another class in my java class that extends base activity and i am trying to access it. Or should i update my question – arinze May 06 '17 at 06:39
0

I was facing this issue for weeks. I literally rewrote my SinchService from scratch, removed Sinch altogether and tried starting fresh but all to no avail. It turns out I was simply initialising my call too early.

I recommend you move the code block:

if ((getSinchServiceInterface() != null || !getSinchServiceInterface().isStarted())) {
            getSinchServiceInterface().startClient(name);
        }

I moved mine to the very end of my onResume method and it seems to all work fine now. The reason this doesn't continually keep starting the client is because we are adding the 'if' statement to make sure it isn't already initialised.

If you find that the issue is still thrown, which was the case for me at one point, try calling it at the very end of the launch of your activity. It simply comes down to being called before your BaseActivity has a chance to initialise mSinchServiceInterface

Brandon Stillitano
  • 1,304
  • 8
  • 27