我在我的应用程序中使用位置融合提供程序,我想将主要活动的Firebase Upstream消息中的纬度和逻辑发送到DashBoard Fragment,其中我有上游消息按钮。我发布了类似的问题,但这不重复。我的问题是为什么我得到空指针异常?
这是mainActivity
中我应该传递数据的方法:
private void updateUI(){
if(null!=mCurrentLocation){
String lat=String.valueOf(mCurrentLocation.getLatitude());
String lot=String.valueOf(mCurrentLocation.getLongitude());
Bundle bundle=new Bundle();
bundle.putString("KEY_LAT", lat);
bundle.putString("KEY_LNG", lot);
DashboardFragment dashboardFragment=new DashboardFragment();
dashboardFragment.setArguments(bundle);
}
这是DashBoardFragment
的一部分,我应该放置纬度和经度:
public void getObjectEvent(EventModel data){
String longitude;
longitude=getArguments().getString("KEY_LNG");
Log.d("LONGITUDE", "Longitude is: " + longitude);
Gson data_json = new Gson();
String json=data_json.toJson(data);
FirebaseMessaging fm=FirebaseMessaging.getInstance();
fm.send(new RemoteMessage.Builder(SENDER_ID + "@gcm.googleapis.com")
.setMessageId(UUID.randomUUID().toString())
.addData("action","message")
.addData("data","{\"message\":\"Upstream Message\"}")
.addData("object", json)
.addData("longitude", longitude)
.build());
}
这是我的空指针:
08-08 14:17:12.755 13165-13165/com.telnet.asp E/AndroidRuntime: FATAL EXCEPTION: main java.lang.NullPointerException
at com.telnet.asp.presentation.view.fragments.DashboardFragment.getObjectEvent(DashboardFragment.java:125)
at com.telnet.asp.presentation.view.adapters.DashboardGridAdapter.getDataObject(DashboardGridAdapter.java:145)
at com.telnet.asp.presentation.view.adapters.DashboardGridAdapter$3.onClick(DashboardGridAdapter.java:128)
at android.support.v7.app.AlertController$ButtonHandler.handleMessage(AlertController.java:157)
at android.os.Handler.dispatchMessage(Handler.java)
at android.os.Looper.loop(Looper.java)
at android.app.ActivityThread.main(ActivityThread.java)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java)
at dalvik.system.NativeStart.main(Native Method)
有人能帮帮我吗? 提前谢谢。