Why don’t you make mNsdUtils
to be a member field if it should be accessed from the outside of the function?
The root cause saying mNsdUtils
is null from the MainActivity.onClickDiscover()
implementation.
Implement in the method itself, as the context is different throwing a null pointer exception.
A small tip for you: read the stack trace and find your source code(for your case, MainActivity.java) to locate what was the first error from bottom to up.
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void com.example.android.implicitintents.Utils.NsdUtils.discoverServices()' on a null object reference
at com.example.android.implicitintents.MainActivity.onClickDiscoverAura(MainActivity.java:40)
at java.lang.reflect.Method.invoke(Native Method)
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288)
at android.view.View.performClick(View.java:5637)
at android.view.View$PerformClick.run(View.java:22429)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
This is the one you need.
at com.example.android.implicitintents.MainActivity.onClickDiscoverAura(MainActivity.java:40)
1
solved Android OnClick and OnclickListner