在将场所保留在列表上之后,用户应查看与该场所关联的饮料。我尝试这样做,但是当我按住场地时,应用程序崩溃了。
这是点击列表生成器的关联代码
listViewVenuesMain.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int i, long l) {
Venue venue = venues.get(i);
showDrinkList(venue.getVenueName());
return false;
}
});
以下是“ showDrinkList”的关联代码:
private void showDrinkList(final String venueName) {
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
LayoutInflater inflater = getLayoutInflater();
final View dialogView = inflater.inflate(R.layout.drink_list, null);
dialogBuilder.setView(dialogView);
//Necessary to get list
listViewDrinksMain = (ListView) dialogView.findViewById(R.id.listViewDrinksMain);
drinks = new ArrayList<>();
String id = databaseVenues.push().getKey();
databaseDrinks = FirebaseDatabase.getInstance().getReference("drinks").child(id);
dialogBuilder.setTitle(venueName + "Deals");
final AlertDialog alertDialog = dialogBuilder.create();
alertDialog.show();
}
这是崩溃日志:
02-16 20:46:40.332 14739 14739 E AndroidRuntime: FATAL EXCEPTION: main
02-16 20:46:40.332 14739 14739 E AndroidRuntime: Process com.example.myapplication, PID: 14739
02-16 20:46:40.332 14739 14739 E AndroidRuntime: java.lang.NullPointerException: Can't pass null for argument 'pathString' in child()
02-16 20:46:40.332 14739 14739 E AndroidRuntime: at com.google.firebase.database.DatabaseReference.child(Unknown Source)
02-16 20:46:40.332 14739 14739 E AndroidRuntime: at com.example.myapplication.UserMainPageActivity.showDrinkList(UserMainPageActivity.java:115)
02-16 20:46:40.332 14739 14739 E AndroidRuntime: at com.example.myapplication.UserMainPageActivity.access$000(UserMainPageActivity.java:28)
02-16 20:46:40.332 14739 14739 E AndroidRuntime: at com.example.myapplication.UserMainPageActivity$1.onItemLongClick(UserMainPageActivity.java:72)
02-16 20:46:40.332 14739 14739 E AndroidRuntime: at android.widget.AbsListView.performLongPress(AbsListView.java:3158)
02-16 20:46:40.332 14739 14739 E AndroidRuntime: at android.widget.AbsListView$CheckForLongPress.run(AbsListView.java:3090)
02-16 20:46:40.332 14739 14739 E AndroidRuntime: at android.os.Handler.handleCallback(Handler.java:746)
02-16 20:46:40.332 14739 14739 E AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:95)
02-16 20:46:40.332 14739 14739 E AndroidRuntime: at android.os.Looper.loop(Looper.java:148)
02-16 20:46:40.332 14739 14739 E AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5443)
02-16 20:46:40.332 14739 14739 E AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
02-16 20:46:40.332 14739 14739 E AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)
02-16 20:46:40.332 14739 14739 E AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
Firebase实时数据库结构: