0

I am trying to compile the Android Location Broadcast code which i downloaded from pubnub site,but I am getting this error while starting sharing my location

10-03 21:09:44.219 31344-31344/io.atlanticlab.pubnubmaptracker E/AndroidRuntime: FATAL EXCEPTION: main Process: io.atlanticlab.pubnubmaptracker, PID: 31344 java.lang.NullPointerException at java.util.Hashtable.put(Hashtable.java:442) at com.pubnub.api.PubnubCore.publish(Unknown Source) at com.pubnub.api.Pubnub.publish(Unknown Source) at io.atlanticlab.pubnubmaptracker.PubNubManager.broadcastLocation(PubNubManager.java:47) at io.atlanticlab.pubnubmaptracker.GMapsShareLocationActivity.onLocationChanged(GMapsShareLocationActivity.java:128) at com.google.android.gms.internal.nj$a.handleMessage(Unknown Source) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:154) at android.app.ActivityThread.main(ActivityThread.java:6236) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:891) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:781)

Here is my PubNubManager.class

public class PubNubManager {

public final static String TAG = "PUBNUB";

public static Pubnub startPubnub() {
    Log.d(TAG, "Initializing PubNub");
    return new Pubnub("demo", "demo");
}

public static void subscribe(Pubnub mPubnub, String channelName, Callback subscribeCallback) {
    // Subscribe to channel
    try {
        mPubnub.subscribe(channelName, subscribeCallback);
        Log.d(TAG, "Subscribed to Channel");
    } catch (PubnubException e) {
        Log.e(TAG, e.toString());
    }
}

public static void broadcastLocation(Pubnub pubnub, String channelName, double latitude,
                                     double longitude, double altitude) {
    JSONObject message = new JSONObject();
    try {
        message.put("lat", latitude);
        message.put("lng", longitude);
        message.put("alt", altitude);
    } catch (JSONException e) {
        Log.e(TAG, e.toString());
    }
    Log.d(TAG, "Sending JSON Message: " + message.toString());
    pubnub.publish(channelName, message, publishCallback);
}

public static Callback publishCallback = new Callback() {

    @Override
    public void successCallback(String channel, Object response) {
        Log.d("PUBNUB", "Sent Message: " + response.toString());
    }

    @Override
    public void errorCallback(String channel, PubnubError error) {
        Log.d("PUBNUB", error.toString());
    }
};

}

Here is the link to whole code link

Tanmay Kajbaje
  • 61
  • 1
  • 3
  • 9
  • which version of the library is this? I do not see com.pubnub.api.PubnubCore in the source code. perhaps move to a newer version... – kandroidj Oct 03 '17 at 15:58
  • Possible duplicate of [What is a NullPointerException, and how do I fix it?](https://stackoverflow.com/questions/218384/what-is-a-nullpointerexception-and-how-do-i-fix-it) – kandroidj Oct 03 '17 at 16:03
  • Can you [enable PubNub client logging](https://www.pubnub.com/docs/android-java/pubnub-android-sdk-troubleshooting-guide), reproduce and share logs? Oh it looks like you are using v3 of the PubNub SDK. If this is a new project, please move to v4 of the SDK. – Craig Conover Oct 04 '17 at 21:09
  • Just wondering if you found any resolution here. – Craig Conover Nov 21 '17 at 21:37

0 Answers0