Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- java.lang.NullPointerException: Provided document path must not be null.
- at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:906)
- at com.google.firebase.firestore.CollectionReference.document(com.google.firebase:firebase-firestore@@18.2.0:110)
- at com.example.home.optometryapplication.AdminUpdateActivity.updateBook(AdminUpdateActivity.java:155)
- at com.example.home.optometryapplication.AdminUpdateActivity.onOptionsItemSelected(AdminUpdateActivity.java:101)
- at android.app.Activity.onMenuItemSelected(Activity.java:3204)
- at android.support.v4.app.FragmentActivity.onMenuItemSelected(FragmentActivity.java:407)
- at android.support.v7.app.AppCompatActivity.onMenuItemSelected(AppCompatActivity.java:195)
- at android.support.v7.view.WindowCallbackWrapper.onMenuItemSelected(WindowCallbackWrapper.java:108)
- at android.support.v7.app.AppCompatDelegateImplV9.onMenuItemSelected(AppCompatDelegateImplV9.java:674)
- at android.support.v7.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:822)
- at android.support.v7.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:171)
- at android.support.v7.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:973)
- at android.support.v7.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:963)
- at android.support.v7.widget.ActionMenuView.invokeItem(ActionMenuView.java:624)
- at android.support.v7.view.menu.ActionMenuItemView.onClick(ActionMenuItemView.java:150)
- at android.view.View.performClick(View.java:5610)
- at android.view.View$PerformClick.run(View.java:22265)
- 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:6077)
- at java.lang.reflect.Method.invoke(Native Method)
- at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
- at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)
- private void updateBook() {
- FirebaseFirestore db = FirebaseFirestore.getInstance();
- String id = getIntent().getStringExtra("id");
- String chapterName = editTextChapterName.getText().toString().trim();
- String chapterInfo = editTextChapterInfo.getText().toString().trim();
- if (chapterName.trim().isEmpty() || chapterInfo.trim().isEmpty()) { //ensure that user has not left boxes empty
- Toast.makeText(this, "Please add a chapter name and the chapter information", Toast.LENGTH_SHORT).show();
- return;
- }
- DocumentReference bookRef = db
- .collection("Book")
- .document(id);
- bookRef
- .update("chapterName", "chapterInfo")
- .addOnSuccessListener(new OnSuccessListener<Void>() {
- @Override
- public void onSuccess(Void aVoid) {
- Log.d(TAG, "DocumentSnapshot updated!");
- }
- })
- .addOnFailureListener(new OnFailureListener() {
- @Override
- public void onFailure(@NonNull Exception e) {
- Log.w(TAG, "Error", e);
- }
- });
- public boolean onOptionsItemSelected(MenuItem item) {
- switch (item.getItemId()) {
- case R.id.save_icon:
- updateBook();
- Intent intent = new Intent(AdminUpdateActivity.this, AdminReadActivity.class);
- startActivity(intent);
- return true;
- default:
- return super.onOptionsItemSelected(item);
- }
- }
- adapter.setOnItemClickListener(new BookAdapter.OnItemClickListener() {
- public void onItemClick(DocumentSnapshot documentSnapshot, int position) {
- Book book = documentSnapshot.toObject(Book.class);
- String id = documentSnapshot.getId();
- String path = documentSnapshot.getReference().getPath();
- Toast.makeText(AdminReadActivity.this,
- "Position: " + position + " ID: " + id, Toast.LENGTH_SHORT).show();
- String chapterName = adapter.getItem(position).getChapterName();
- String chapterInfo = adapter.getItem(position).getChapterInfo();
- Integer chapterNumber = adapter.getItem(position).getChapterNumber();
- Intent intent = new Intent(AdminReadActivity.this, AdminUpdateActivity.class);
- intent.putExtra("mChapterName", chapterName);
- intent.putExtra("mChapterInfo", chapterInfo);
- intent.putExtra("mChapterNumber", chapterNumber);
- intent.putExtra("mMyId", id);
- startActivity(intent);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement