SHARE
TWEET

Untitled

a guest Jun 25th, 2019 43 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. java.lang.NullPointerException: Provided document path must not be null.
  2.         at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:906)
  3.         at com.google.firebase.firestore.CollectionReference.document(com.google.firebase:firebase-firestore@@18.2.0:110)
  4.         at com.example.home.optometryapplication.AdminUpdateActivity.updateBook(AdminUpdateActivity.java:155)
  5.         at com.example.home.optometryapplication.AdminUpdateActivity.onOptionsItemSelected(AdminUpdateActivity.java:101)
  6.         at android.app.Activity.onMenuItemSelected(Activity.java:3204)
  7.         at android.support.v4.app.FragmentActivity.onMenuItemSelected(FragmentActivity.java:407)
  8.         at android.support.v7.app.AppCompatActivity.onMenuItemSelected(AppCompatActivity.java:195)
  9.         at android.support.v7.view.WindowCallbackWrapper.onMenuItemSelected(WindowCallbackWrapper.java:108)
  10.         at android.support.v7.app.AppCompatDelegateImplV9.onMenuItemSelected(AppCompatDelegateImplV9.java:674)
  11.         at android.support.v7.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:822)
  12.         at android.support.v7.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:171)
  13.         at android.support.v7.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:973)
  14.         at android.support.v7.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:963)
  15.         at android.support.v7.widget.ActionMenuView.invokeItem(ActionMenuView.java:624)
  16.         at android.support.v7.view.menu.ActionMenuItemView.onClick(ActionMenuItemView.java:150)
  17.         at android.view.View.performClick(View.java:5610)
  18.         at android.view.View$PerformClick.run(View.java:22265)
  19.         at android.os.Handler.handleCallback(Handler.java:751)
  20.         at android.os.Handler.dispatchMessage(Handler.java:95)
  21.         at android.os.Looper.loop(Looper.java:154)
  22.         at android.app.ActivityThread.main(ActivityThread.java:6077)
  23.         at java.lang.reflect.Method.invoke(Native Method)
  24.         at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
  25.         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)
  26.      
  27. private void updateBook() {
  28.  
  29.         FirebaseFirestore db = FirebaseFirestore.getInstance();
  30.  
  31.         String id = getIntent().getStringExtra("id");
  32.         String chapterName = editTextChapterName.getText().toString().trim();
  33.         String chapterInfo = editTextChapterInfo.getText().toString().trim();
  34.  
  35.         if (chapterName.trim().isEmpty() || chapterInfo.trim().isEmpty()) { //ensure that user has not left boxes empty
  36.             Toast.makeText(this, "Please add a chapter name and the chapter information", Toast.LENGTH_SHORT).show();
  37.             return;
  38.         }
  39.  
  40.         DocumentReference bookRef = db
  41.                 .collection("Book")
  42.                 .document(id);
  43.         bookRef
  44.                 .update("chapterName", "chapterInfo")
  45.                 .addOnSuccessListener(new OnSuccessListener<Void>() {
  46.                     @Override
  47.                     public void onSuccess(Void aVoid) {
  48.                         Log.d(TAG, "DocumentSnapshot updated!");
  49.                     }
  50.                 })
  51.                 .addOnFailureListener(new OnFailureListener() {
  52.                     @Override
  53.                     public void onFailure(@NonNull Exception e) {
  54.                         Log.w(TAG, "Error", e);
  55.                     }
  56.                 });
  57.      
  58. public boolean onOptionsItemSelected(MenuItem item) {
  59.         switch (item.getItemId()) {
  60.             case R.id.save_icon:
  61.                 updateBook();
  62.                 Intent intent = new Intent(AdminUpdateActivity.this, AdminReadActivity.class);
  63.                 startActivity(intent);
  64.             return true;
  65.             default:
  66.                 return super.onOptionsItemSelected(item);
  67.         }
  68.  
  69.     }
  70.      
  71. adapter.setOnItemClickListener(new BookAdapter.OnItemClickListener() {
  72.  
  73.             public void onItemClick(DocumentSnapshot documentSnapshot, int position) {
  74.                 Book book = documentSnapshot.toObject(Book.class);
  75.                 String id = documentSnapshot.getId();
  76.                 String path = documentSnapshot.getReference().getPath();
  77.                 Toast.makeText(AdminReadActivity.this,
  78.                         "Position: " + position + " ID: " + id, Toast.LENGTH_SHORT).show();
  79.  
  80.                 String chapterName = adapter.getItem(position).getChapterName();
  81.                 String chapterInfo = adapter.getItem(position).getChapterInfo();
  82.                 Integer chapterNumber = adapter.getItem(position).getChapterNumber();
  83.  
  84.  
  85.                 Intent intent = new Intent(AdminReadActivity.this, AdminUpdateActivity.class);
  86.  
  87.                 intent.putExtra("mChapterName", chapterName);
  88.                 intent.putExtra("mChapterInfo", chapterInfo);
  89.                 intent.putExtra("mChapterNumber", chapterNumber);
  90.                 intent.putExtra("mMyId", id);
  91.  
  92.                 startActivity(intent);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top