我正在尝试编译从pubnub网站下载的Android位置广播代码,但我在开始分享我的位置时收到此错误
10-03 21:09:44.219 31344-31344 / io.atlanticlab.pubnubmaptracker E / AndroidRuntime:FATAL EXCEPTION:main 流程:io.atlanticlab.pubnubmaptracker,PID:31344 显示java.lang.NullPointerException 在java.util.Hashtable.put(Hashtable.java:442) 在com.pubnub.api.PubnubCore.publish(未知来源) 在com.pubnub.api.Pubnub.publish(未知来源) 在io.atlanticlab.pubnubmaptracker.PubNubManager.broadcastLocation(PubNubManager.java:47) 在io.atlanticlab.pubnubmaptracker.GMapsShareLocationActivity.onLocationChanged(GMapsShareLocationActivity.java:128) 在com.google.android.gms.internal.nj $ a.handleMessage(未知来源) 在android.os.Handler.dispatchMessage(Handler.java:102) 在android.os.Looper.loop(Looper.java:154) 在android.app.ActivityThread.main(ActivityThread.java:6236) at java.lang.reflect.Method.invoke(Native Method) 在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:891) 在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:781)
这是我的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());
}
};
}
以下是整个代码的链接 link