Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/202.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何获得FireStore使用Android生成的唯一用户ID? package com.example.finaltry; 导入androidx.annotation.NonNull; 导入androidx.appcompat.app.appcompat活动; 导入androidx.recyclerview.widget.LinearLayoutManager; 导入androidx.recyclerview.widget.recyclerview; 导入android.content.Context; 导入android.os.Bundle; 导入android.util.Log; 导入android.widget.ImageView; 导入android.widget.RatingBar; 导入android.widget.TextView; 导入android.widget.Toast; 导入com.google.android.gms.tasks.OnCompleteListener; 导入com.google.android.gms.tasks.OnFailureListener; 导入com.google.android.gms.tasks.Task; 导入com.google.firebase.auth.FirebaseAuth; 导入com.google.firebase.firestore.CollectionReference; 导入com.google.firebase.firestore.DocumentReference; 导入com.google.firebase.firestore.DocumentSnapshot; 导入com.google.firebase.firestore.FirebaseFirestore; 导入com.google.firebase.firestore.QuerySnapshot; 导入java.util.ArrayList; 导入java.util.List; 公共类VendorDisplayaActivity扩展了AppCompativeActivity{ 私有静态最终字符串TAG=“TAG”; TextView textViewVendorName; 图像视图供应商图像; 评级杆评级; 私有FirebaseFirestore db=FirebaseFirestore.getInstance(); 私有FirebaseAuth FirebaseAuth=FirebaseAuth.getInstance(); CollectionReference供应商\库存\详细信息\参考=db.集合(“供应商\详细信息”); 文件参考ven_Ref=数据库文件(“供应商详细信息”); 字符串sid; 回收视图mRecyclerView; //这只是AP的一次尝试 List modelList=新的ArrayList(); RecyclerView.LayoutManager LayoutManager; 产品定制适配器; 语境; @凌驾 创建时受保护的void(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.activity\u vendor\u display); 最后一个字符串vname=getIntent().getStringExtra(“v_name”); 最终字符串pid=getIntent().getStringExtra(“p_id”); Toast.makeText(getApplicationContext(),vname,Toast.LENGTH_SHORT).show(); textViewVendorName=findViewById(R.id.textViewVendorName); vendorImage=findviewbyd(R.id.imageViewVendor); 评级=findViewById(R.id.RatingBar供应商); 上下文=这个; mRecyclerView=findviewbyd(R.id.recyclerview\u产品); //设置回收器视图属性 mRecyclerView.setHasFixedSize(true); layoutManager=新的LinearLayoutManager(getApplicationContext()); mRecyclerView.setLayoutManager(layoutManager); 供应商\库存\详细信息\参考 .whereEqualTo(“品牌名称”,vname) .get() .addOnCompleteListener(新的OnCompleteListener(){ @凌驾 未完成的公共void(@NonNull任务){ 日志d(标记为“步骤2”); 对于(DocumentSnapshot文档:task.getResult()){ sid=doc.getId(); 日志d(标记为“步骤3”); } 日志d(标记为“步骤4”); Toast.makeText(getApplicationContext(),sid,Toast.LENGTH_SHORT.show(); } }).addOnFailureListener(新的OnFailureListener(){ @凌驾 public void onFailure(@NonNull异常e){ 日志d(标记为“步骤5”); Toast.makeText(getApplicationContext(),e.getMessage(),Toast.LENGTH_SHORT).show(); } }); //Toast.makeText(getApplicationContext(),pid,Toast.LENGTH_SHORT.show(); //sid=“N1GQdOXUSLRS1dREfu5SltVKoBb2”; Toast.makeText(getApplicationContext(),vname,Toast.LENGTH_SHORT).show(); 供应商库存详细信息参考文件(sid)收集(“库存”) .get() .addOnCompleteListener(新的OnCompleteListener(){ @凌驾 未完成的公共void(@NonNull任务){ modelList.clear(); 对于(DocumentSnapshot文档:task.getResult()){ ProductModel ProductModel=新的ProductModel(doc.getString(“ProductName”), doc.getString(“Rate”)、doc.getString(“ProductId”); 添加(productModel); } adapter=新产品CustomAdapter(VendorDisplayActivity.this、modelList、context); mRecyclerView.setAdapter(适配器); } }).addOnFailureListener(新的OnFailureListener(){ @凌驾 public void onFailure(@NonNull异常e){ Toast.makeText(getApplicationContext(),e.getMessage(),Toast.LENGTH_SHORT).show(); } }); } }_Java_Android_Firebase_Google Cloud Firestore - Fatal编程技术网

如何获得FireStore使用Android生成的唯一用户ID? package com.example.finaltry; 导入androidx.annotation.NonNull; 导入androidx.appcompat.app.appcompat活动; 导入androidx.recyclerview.widget.LinearLayoutManager; 导入androidx.recyclerview.widget.recyclerview; 导入android.content.Context; 导入android.os.Bundle; 导入android.util.Log; 导入android.widget.ImageView; 导入android.widget.RatingBar; 导入android.widget.TextView; 导入android.widget.Toast; 导入com.google.android.gms.tasks.OnCompleteListener; 导入com.google.android.gms.tasks.OnFailureListener; 导入com.google.android.gms.tasks.Task; 导入com.google.firebase.auth.FirebaseAuth; 导入com.google.firebase.firestore.CollectionReference; 导入com.google.firebase.firestore.DocumentReference; 导入com.google.firebase.firestore.DocumentSnapshot; 导入com.google.firebase.firestore.FirebaseFirestore; 导入com.google.firebase.firestore.QuerySnapshot; 导入java.util.ArrayList; 导入java.util.List; 公共类VendorDisplayaActivity扩展了AppCompativeActivity{ 私有静态最终字符串TAG=“TAG”; TextView textViewVendorName; 图像视图供应商图像; 评级杆评级; 私有FirebaseFirestore db=FirebaseFirestore.getInstance(); 私有FirebaseAuth FirebaseAuth=FirebaseAuth.getInstance(); CollectionReference供应商\库存\详细信息\参考=db.集合(“供应商\详细信息”); 文件参考ven_Ref=数据库文件(“供应商详细信息”); 字符串sid; 回收视图mRecyclerView; //这只是AP的一次尝试 List modelList=新的ArrayList(); RecyclerView.LayoutManager LayoutManager; 产品定制适配器; 语境; @凌驾 创建时受保护的void(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.activity\u vendor\u display); 最后一个字符串vname=getIntent().getStringExtra(“v_name”); 最终字符串pid=getIntent().getStringExtra(“p_id”); Toast.makeText(getApplicationContext(),vname,Toast.LENGTH_SHORT).show(); textViewVendorName=findViewById(R.id.textViewVendorName); vendorImage=findviewbyd(R.id.imageViewVendor); 评级=findViewById(R.id.RatingBar供应商); 上下文=这个; mRecyclerView=findviewbyd(R.id.recyclerview\u产品); //设置回收器视图属性 mRecyclerView.setHasFixedSize(true); layoutManager=新的LinearLayoutManager(getApplicationContext()); mRecyclerView.setLayoutManager(layoutManager); 供应商\库存\详细信息\参考 .whereEqualTo(“品牌名称”,vname) .get() .addOnCompleteListener(新的OnCompleteListener(){ @凌驾 未完成的公共void(@NonNull任务){ 日志d(标记为“步骤2”); 对于(DocumentSnapshot文档:task.getResult()){ sid=doc.getId(); 日志d(标记为“步骤3”); } 日志d(标记为“步骤4”); Toast.makeText(getApplicationContext(),sid,Toast.LENGTH_SHORT.show(); } }).addOnFailureListener(新的OnFailureListener(){ @凌驾 public void onFailure(@NonNull异常e){ 日志d(标记为“步骤5”); Toast.makeText(getApplicationContext(),e.getMessage(),Toast.LENGTH_SHORT).show(); } }); //Toast.makeText(getApplicationContext(),pid,Toast.LENGTH_SHORT.show(); //sid=“N1GQdOXUSLRS1dREfu5SltVKoBb2”; Toast.makeText(getApplicationContext(),vname,Toast.LENGTH_SHORT).show(); 供应商库存详细信息参考文件(sid)收集(“库存”) .get() .addOnCompleteListener(新的OnCompleteListener(){ @凌驾 未完成的公共void(@NonNull任务){ modelList.clear(); 对于(DocumentSnapshot文档:task.getResult()){ ProductModel ProductModel=新的ProductModel(doc.getString(“ProductName”), doc.getString(“Rate”)、doc.getString(“ProductId”); 添加(productModel); } adapter=新产品CustomAdapter(VendorDisplayActivity.this、modelList、context); mRecyclerView.setAdapter(适配器); } }).addOnFailureListener(新的OnFailureListener(){ @凌驾 public void onFailure(@NonNull异常e){ Toast.makeText(getApplicationContext(),e.getMessage(),Toast.LENGTH_SHORT).show(); } }); } }

如何获得FireStore使用Android生成的唯一用户ID? package com.example.finaltry; 导入androidx.annotation.NonNull; 导入androidx.appcompat.app.appcompat活动; 导入androidx.recyclerview.widget.LinearLayoutManager; 导入androidx.recyclerview.widget.recyclerview; 导入android.content.Context; 导入android.os.Bundle; 导入android.util.Log; 导入android.widget.ImageView; 导入android.widget.RatingBar; 导入android.widget.TextView; 导入android.widget.Toast; 导入com.google.android.gms.tasks.OnCompleteListener; 导入com.google.android.gms.tasks.OnFailureListener; 导入com.google.android.gms.tasks.Task; 导入com.google.firebase.auth.FirebaseAuth; 导入com.google.firebase.firestore.CollectionReference; 导入com.google.firebase.firestore.DocumentReference; 导入com.google.firebase.firestore.DocumentSnapshot; 导入com.google.firebase.firestore.FirebaseFirestore; 导入com.google.firebase.firestore.QuerySnapshot; 导入java.util.ArrayList; 导入java.util.List; 公共类VendorDisplayaActivity扩展了AppCompativeActivity{ 私有静态最终字符串TAG=“TAG”; TextView textViewVendorName; 图像视图供应商图像; 评级杆评级; 私有FirebaseFirestore db=FirebaseFirestore.getInstance(); 私有FirebaseAuth FirebaseAuth=FirebaseAuth.getInstance(); CollectionReference供应商\库存\详细信息\参考=db.集合(“供应商\详细信息”); 文件参考ven_Ref=数据库文件(“供应商详细信息”); 字符串sid; 回收视图mRecyclerView; //这只是AP的一次尝试 List modelList=新的ArrayList(); RecyclerView.LayoutManager LayoutManager; 产品定制适配器; 语境; @凌驾 创建时受保护的void(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.activity\u vendor\u display); 最后一个字符串vname=getIntent().getStringExtra(“v_name”); 最终字符串pid=getIntent().getStringExtra(“p_id”); Toast.makeText(getApplicationContext(),vname,Toast.LENGTH_SHORT).show(); textViewVendorName=findViewById(R.id.textViewVendorName); vendorImage=findviewbyd(R.id.imageViewVendor); 评级=findViewById(R.id.RatingBar供应商); 上下文=这个; mRecyclerView=findviewbyd(R.id.recyclerview\u产品); //设置回收器视图属性 mRecyclerView.setHasFixedSize(true); layoutManager=新的LinearLayoutManager(getApplicationContext()); mRecyclerView.setLayoutManager(layoutManager); 供应商\库存\详细信息\参考 .whereEqualTo(“品牌名称”,vname) .get() .addOnCompleteListener(新的OnCompleteListener(){ @凌驾 未完成的公共void(@NonNull任务){ 日志d(标记为“步骤2”); 对于(DocumentSnapshot文档:task.getResult()){ sid=doc.getId(); 日志d(标记为“步骤3”); } 日志d(标记为“步骤4”); Toast.makeText(getApplicationContext(),sid,Toast.LENGTH_SHORT.show(); } }).addOnFailureListener(新的OnFailureListener(){ @凌驾 public void onFailure(@NonNull异常e){ 日志d(标记为“步骤5”); Toast.makeText(getApplicationContext(),e.getMessage(),Toast.LENGTH_SHORT).show(); } }); //Toast.makeText(getApplicationContext(),pid,Toast.LENGTH_SHORT.show(); //sid=“N1GQdOXUSLRS1dREfu5SltVKoBb2”; Toast.makeText(getApplicationContext(),vname,Toast.LENGTH_SHORT).show(); 供应商库存详细信息参考文件(sid)收集(“库存”) .get() .addOnCompleteListener(新的OnCompleteListener(){ @凌驾 未完成的公共void(@NonNull任务){ modelList.clear(); 对于(DocumentSnapshot文档:task.getResult()){ ProductModel ProductModel=新的ProductModel(doc.getString(“ProductName”), doc.getString(“Rate”)、doc.getString(“ProductId”); 添加(productModel); } adapter=新产品CustomAdapter(VendorDisplayActivity.this、modelList、context); mRecyclerView.setAdapter(适配器); } }).addOnFailureListener(新的OnFailureListener(){ @凌驾 public void onFailure(@NonNull异常e){ Toast.makeText(getApplicationContext(),e.getMessage(),Toast.LENGTH_SHORT).show(); } }); } },java,android,firebase,google-cloud-firestore,Java,Android,Firebase,Google Cloud Firestore,我的问题是如何生成sid,因为当我为sid设置静态值时,应用程序运行正常。 如果未提供sid,则错误为:NullPointerException 若我删除注释并将静态值放在sid中,它就会工作 另外,我正在创建从事件管理器配置文件到供应商配置文件的搜索功能,那么如何解决这个问题呢 get()是异步的,在查询结果完成之前立即返回。您的回调将在一段时间后调用,并显示结果 现在,你的代码 package com.example.finaltry; import androidx.annotation

我的问题是如何生成sid,因为当我为sid设置静态值时,应用程序运行正常。 如果未提供sid,则错误为:NullPointerException 若我删除注释并将静态值放在sid中,它就会工作 另外,我正在创建从事件管理器配置文件到供应商配置文件的搜索功能,那么如何解决这个问题呢

get()
是异步的,在查询结果完成之前立即返回。您的回调将在一段时间后调用,并显示结果

现在,你的代码
package com.example.finaltry;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.widget.ImageView;
import android.widget.RatingBar;
import android.widget.TextView;
import android.widget.Toast;

import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.OnFailureListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.firestore.CollectionReference;
import com.google.firebase.firestore.DocumentReference;
import com.google.firebase.firestore.DocumentSnapshot;
import com.google.firebase.firestore.FirebaseFirestore;
import com.google.firebase.firestore.QuerySnapshot;

import java.util.ArrayList;
import java.util.List;

public class VendorDisplayActivity extends AppCompatActivity {

    private static final String TAG = "TAG";
    TextView textViewVendorName;
    ImageView vendorImage;
    RatingBar rating;

    private FirebaseFirestore db = FirebaseFirestore.getInstance();
    private FirebaseAuth firebaseAuth = FirebaseAuth.getInstance();
    CollectionReference vendor_inventory_details_Ref = db.collection("Vendor_Details");
    DocumentReference ven_Ref = db.document("Vendor_Details");

    String sid ;
    RecyclerView mRecyclerView;

    //this is just for try of AP
    List<ProductModel> modelList = new ArrayList<>();
    RecyclerView.LayoutManager layoutManager;
    ProductCustomAdapter adapter;
    Context context;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_vendor_display);

        final String vname=getIntent().getStringExtra("v_name");
        final String pid=getIntent().getStringExtra("p_id");

        Toast.makeText(getApplicationContext(),vname,Toast.LENGTH_SHORT).show();

        textViewVendorName = findViewById(R.id.textViewVendorName);
        vendorImage = findViewById(R.id.imageViewVendor);
        rating = findViewById(R.id.ratingBarVendor);
        context = this;

        mRecyclerView =findViewById(R.id.recyclerview_Product);

        //set recycler views properties
        mRecyclerView.setHasFixedSize(true);
        layoutManager = new LinearLayoutManager(getApplicationContext());
        mRecyclerView.setLayoutManager(layoutManager);


        vendor_inventory_details_Ref
                .whereEqualTo("Brand_Name",vname)
                .get()
                .addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
                                            @Override
                                           public void onComplete(@NonNull Task<QuerySnapshot> task) {
                                               Log.d(TAG,"Step2 ");
                                               for (DocumentSnapshot doc: task.getResult()){
                                                   sid=doc.getId();
                                                   Log.d(TAG,"Step3 ");

                                               }
                                               Log.d(TAG,"Step4 ");
                                               Toast.makeText(getApplicationContext(),sid,Toast.LENGTH_SHORT).show();

                                           }
                                       }).addOnFailureListener(new OnFailureListener() {
            @Override
            public void onFailure(@NonNull Exception e) {
                Log.d(TAG,"Step5 ");

                Toast.makeText(getApplicationContext(),e.getMessage(),Toast.LENGTH_SHORT).show();

            }
        });

        //Toast.makeText(getApplicationContext(),pid,Toast.LENGTH_SHORT).show();
       // sid="N1GQdOXUSLRS1dREfu5SltVKoBb2";
        Toast.makeText(getApplicationContext(),vname,Toast.LENGTH_SHORT).show();
        vendor_inventory_details_Ref.document(sid).collection("Inventory")
                                .get()
                                .addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
                                    @Override
                                    public void onComplete(@NonNull Task<QuerySnapshot> task) {
                                        modelList.clear();
                                        for (DocumentSnapshot doc : task.getResult()) {
                                            ProductModel productModel = new ProductModel(doc.getString("ProductName"),
                                                    doc.getString("Rate"), doc.getString("ProductId"));
                                            modelList.add(productModel);
                                        }
                                        adapter = new ProductCustomAdapter(VendorDisplayActivity.this, modelList, context);
                                        mRecyclerView.setAdapter(adapter);
                                    }
                                }).addOnFailureListener(new OnFailureListener() {
                            @Override
                            public void onFailure(@NonNull Exception e) {

                                Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_SHORT).show();
                            }
                        });






    }
}