Я пытаюсь получить данные из Firebase Firestore во вложенный вид переработчика. У меня есть класс ItemClass и SubItem.
Вот моя функция onCreateView:
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View rootView = inflater.inflate(R.layout.fragment_order__subscription_0, container, false);
recyclerView = (RecyclerView)rootView.findViewById(R.id.recycViewSubscription);
linearLayoutManager = new LinearLayoutManager(getContext());
recyclerView.setLayoutManager(linearLayoutManager);
/* Adding Customer Data in Recycler View from Firebase */
final List<CustomerClass> itemList = new ArrayList<>();
final FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
Log.d(TAG, user.getUid());
CollectionReference users = db.collection("Users").document(user.getUid()).collection("Order_Subscription");
users.get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
@Override
public void onComplete(@NonNull Task<QuerySnapshot> task) {
if (task.isSuccessful()) {
for (QueryDocumentSnapshot document : task.getResult()) {
Log.d(TAG, "DocumentSnapshot data: " + document.getData());
final Map<String, Object> m = document.getData();
/* Getting Subitem for the current Customer */
Log.d(TAG, "Reached before subtask"+document.getId().toString());
Log.d(TAG, document.getId().toString());
CollectionReference orders = db.collection("Users").document(user.getUid()).collection("Order_Subscription").document(document.getId().toString()).collection("OrdersByCustomer");
final List<CustProduct_Subclass> subItemList = new ArrayList<>();
orders.get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
@Override
public void onComplete(@NonNull Task<QuerySnapshot> subtask) {
Log.d(TAG, "Reached inside subtask");
if (subtask.isSuccessful()) {
for (QueryDocumentSnapshot subdocument : subtask.getResult()) {
Log.d(TAG, "DocumentSnapshot Subdata: " + subdocument.getData());
Map<String, Object> n = subdocument.getData();
Log.d(TAG,"Name"+n.get("ProductName").toString());
CustProduct_Subclass subItem = new CustProduct_Subclass(n.get("ProductName").toString(), n.get("Quantity").toString(), n.get("Amount").toString(), n.get("Description").toString(), n.get("Delivered").toString());
subItemList.add(subItem);
n.clear();
}
//Log.d(TAG,"Name"+m.get("CustomerName").toString());
Log.d(TAG, "sublistsize"+subItemList.size()+"");
customerClass = new CustomerClass(m.get("CustomerName").toString(), m.get("Address").toString(), m.get("MobileNumber").toString(), subItemList);
itemList.add(customerClass);
} else {
Log.d(TAG, "Reached inside subtask");
Log.d(TAG, "Error getting documents.", subtask.getException());
}
}
});
/* Subitem part done */
Log.d(TAG, "Finished Subtask");
m.clear();
}
Log.d(TAG, "listsize"+itemList.size()+"");
itemAdapter = new ItemAdapter(itemList);
recyclerView.setAdapter(itemAdapter);
} else {
Log.w(TAG, "Error getting documents.", task.getException());
}
}
});
// ItemAdapter itemAdapter = new ItemAdapter(buildItemList());
return rootView;
}
Вот моя структура базы данных [
Для этой спецификации c vendor, я нахожу список Customer, Item и для каждого клиента, их заказы, подпункты.
Я поместил записи журнала в CustomerClass и CustProduct_Subclass.
Я получаю следующие ошибки.
2020-04-28 10:54:25.312 30675-30819/com.example.organicindiapre D/OpenGLRenderer: CacheTexture 3 upload: x, y, width height = 164, 224, 18, 20
2020-04-28 10:54:33.064 30675-30675/com.example.organicindiapre D/Constraints: nf9sQL0PUpRPjXkAdnhr7Xrlotp1
2020-04-28 10:54:33.088 30675-30675/com.example.organicindiapre D/Constraints: CustomerClass Created
2020-04-28 10:54:33.088 30675-30675/com.example.organicindiapre D/Constraints: CustomerClass Created
2020-04-28 10:54:33.088 30675-30675/com.example.organicindiapre D/Constraints: CustomerClass Created
2020-04-28 10:54:33.088 30675-30675/com.example.organicindiapre D/Constraints: CustomerClass Created
2020-04-28 10:54:33.088 30675-30675/com.example.organicindiapre D/Constraints: CustomerClass Created
2020-04-28 10:54:33.102 30675-30990/com.example.organicindiapre W/DynamiteModule: Local module descriptor class for providerinstaller not found.
2020-04-28 10:54:33.106 30675-30675/com.example.organicindiapre E/RecyclerView: No adapter attached; skipping layout
2020-04-28 10:54:33.122 30675-30990/com.example.organicindiapre I/DynamiteModule: Considering local module providerinstaller:0 and remote module providerinstaller:0
2020-04-28 10:54:33.122 30675-30990/com.example.organicindiapre W/ProviderInstaller: Failed to load providerinstaller module: No acceptable module found. Local version is 0 and remote version is 0.
2020-04-28 10:54:33.194 30675-30990/com.example.organicindiapre D/ApplicationLoaders: ignored Vulkan layer search path /data/app/com.google.android.gms-2/lib/arm:/data/app/com.google.android.gms-2/base.apk!/lib/armeabi-v7a for namespace 0xa8722090
2020-04-28 10:54:33.231 30675-30990/com.example.organicindiapre V/NativeCrypto: Registering com/google/android/gms/org/conscrypt/NativeCrypto's 286 native methods...
2020-04-28 10:54:33.323 30675-30990/com.example.organicindiapre D/NetworkSecurityConfig: No Network Security Config specified, using platform default
2020-04-28 10:54:33.329 30675-30990/com.example.organicindiapre I/ProviderInstaller: Installed default security provider GmsCore_OpenSSL
2020-04-28 10:54:33.330 30675-30819/com.example.organicindiapre D/OpenGLRenderer: CacheTexture 3 upload: x, y, width height = 64, 0, 173, 442
2020-04-28 10:54:33.330 30675-30819/com.example.organicindiapre D/OpenGLRenderer: ProgramCache.generateProgram: 5242944
2020-04-28 10:54:33.428 30675-30990/com.example.organicindiapre W/art: Before Android 4.1, method double java.util.concurrent.ThreadLocalRandom.internalNextDouble(double, double) would have incorrectly overridden the package-private method in java.util.Random
2020-04-28 10:54:33.429 30675-30990/com.example.organicindiapre W/art: Before Android 4.1, method int java.util.concurrent.ThreadLocalRandom.internalNextInt(int, int) would have incorrectly overridden the package-private method in java.util.Random
2020-04-28 10:54:33.429 30675-30990/com.example.organicindiapre W/art: Before Android 4.1, method long java.util.concurrent.ThreadLocalRandom.internalNextLong(long, long) would have incorrectly overridden the package-private method in java.util.Random
2020-04-28 10:54:33.616 30675-30995/com.example.organicindiapre D/libc-netbsd: getaddrinfo: firestore.googleapis.com get result from proxy gai_error = 0
2020-04-28 10:54:33.635 30675-30997/com.example.organicindiapre I/System.out: [socket][0] connection firestore.googleapis.com/2404:6800:4007:809::200a:443;LocalPort=-1(0)
2020-04-28 10:54:33.711 30675-30997/com.example.organicindiapre I/System.out: [socket][/2401:4900:2100:2869:2:4:3f4a:e9da:55792] connected
2020-04-28 10:54:34.816 30675-30675/com.example.organicindiapre D/Constraints: DocumentSnapshot data: {MobileNumber=PhoneNumber, CustomerName=SomeName, Address=Address1}
2020-04-28 10:54:34.817 30675-30675/com.example.organicindiapre D/Constraints: Reached before subtaskCustomerID
2020-04-28 10:54:34.817 30675-30675/com.example.organicindiapre D/Constraints: CustomerID
2020-04-28 10:54:34.818 30675-30675/com.example.organicindiapre D/Constraints: Finished Subtask
2020-04-28 10:54:34.818 30675-30675/com.example.organicindiapre D/Constraints: listsize0
2020-04-28 10:54:35.650 30675-30675/com.example.organicindiapre D/Constraints: Reached inside subtask
2020-04-28 10:54:35.650 30675-30675/com.example.organicindiapre D/Constraints: DocumentSnapshot Subdata: {ProductName=Product 1, Description=, Quantity=5, Delivered=false, Amount=1232}
2020-04-28 10:54:35.651 30675-30675/com.example.organicindiapre D/Constraints: NameProduct 1
2020-04-28 10:54:35.651 30675-30675/com.example.organicindiapre D/Constraints: CustomerSubClass Created
2020-04-28 10:54:35.651 30675-30675/com.example.organicindiapre D/Constraints: sublistsize1
2020-04-28 10:54:35.655 30675-30675/com.example.organicindiapre D/AndroidRuntime: Shutting down VM
2020-04-28 10:54:35.656 30675-30675/com.example.organicindiapre E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.organicindiapre, PID: 30675
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String java.lang.Object.toString()' on a null object reference
at com.example.organicindiapre.vendor.Order_Subscription$1$1.onComplete(Order_Subscription.java:136)
at com.google.android.gms.tasks.zzj.run(Unknown Source)
at android.os.Handler.handleCallback(Handler.java:836)
at android.os.Handler.dispatchMessage(Handler.java:103)
at android.os.Looper.loop(Looper.java:203)
at android.app.ActivityThread.main(ActivityThread.java:6339)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1084)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:945)
В первых нескольких строках журнала я не понимаю, почему создаются 5 CustomerClasses. Существует только один Customer и 1 Product, который они заказывают. Тогда главная ошибка ниже.