当我尝试打开数据库存储写入器时,android studio 无法打开下一页或有时显示“保持停止”消息

问题描述

  1. android studio 无法打开下一页或有时显示“保留” 当我尝试打开数据库存储写入器时停止”消息
  2. 但一切正常,一切都从我尝试包含数据存储开始

运行直到选择类别并返回登录页面

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_admin_add_new_product);

        categoryName = getIntent().getExtras().get("category").toString();

        Toast.makeText(this,"Выбрана категория" + categoryName,Toast.LENGTH_SHORT).show();

选择类别中必须是将产品添加到存储中的按钮

productimage.setonClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Opengallery();
        }
    });

    addNewProductButton.setonClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            ValidateProductData();
        }
    });
}

private void ValidateProductData() {

    Description = product_description.getText().toString();
    Price = product_price.getText().toString();
    PName = product_name.getText().toString();

    if(ImageUri == null){
        Toast.makeText(this,"Добавьте изображение товара",Toast.LENGTH_SHORT).show();
    }
    else if(TextUtils.isEmpty(Description)) {
        Toast.makeText(this,"Добавьте описание товара",Toast.LENGTH_SHORT).show();
    }
    else if(TextUtils.isEmpty(Price)) {
        Toast.makeText(this,"Добавьте стоимость товара",Toast.LENGTH_SHORT).show();
    }
    else if(TextUtils.isEmpty(PName)) {
        Toast.makeText(this,"Добавьте название товара",Toast.LENGTH_SHORT).show();
    }
    else{
        StoreProduct@R_118_4045@ion();

    }

}





private void StoreProduct@R_118_4045@ion() {

    loadingBar.setTitle("Загрузка Данных");
    loadingBar.setMessage("Пожалуйста подождите");
    loadingBar.setCanceledOnTouchOutside(false);
    loadingBar.show();

    Calendar calendar = Calendar.getInstance();

    SimpleDateFormat currentDate = new SimpleDateFormat("ddMMyyyy");
    SaveCurrentDate = currentDate.format(calendar.getTime());

    SimpleDateFormat currentTime = new SimpleDateFormat("HHmmss");
    SaveCurrentTime = currentTime.format(calendar.getTime());

    ProductRandomKey = SaveCurrentDate + SaveCurrentTime;

    final StorageReference filePath = ProductimageRef.child(ImageUri.getLastPathSegment() + ProductRandomKey + ".jpg");

    final UploadTask uploadTask = filePath.putFile(ImageUri);

    uploadTask.addOnFailureListener(new OnFailureListener() {
        @Override
        public void onFailure(@NonNull Exception e) {
            String message = e.toString();
                Toast.makeText(AdminAddNewProductActivity.this,"Ошибка: " + message,Toast.LENGTH_SHORT).show();
                loadingBar.dismiss();
        }
    }).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
        @Override
        public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
                Toast.makeText(AdminAddNewProductActivity.this,"Изображение успешно загружено",Toast.LENGTH_SHORT).show();

                Task<Uri> uriTask = uploadTask.continueWithTask(new Continuation<UploadTask.TaskSnapshot,Task<Uri>>() {
                    @Override
                    public Task<Uri> then(@NonNull Task<UploadTask.TaskSnapshot> task) throws Exception {
                       if(!task.isSuccessful()){
                           throw task.getException();
                       }
                       downloadImageUrl = filePath.getDownloadUrl().toString();
                       return filePath.getDownloadUrl();
                    }
                }).addOnCompleteListener(new OnCompleteListener<Uri>() {
                    @Override
                    public void onComplete(@NonNull Task<Uri> task) {
                        if(task.isSuccessful()){
                            Toast.makeText(AdminAddNewProductActivity.this,"Фото сохранено",Toast.LENGTH_SHORT).show();

                            SaveProductInfoToDatabase();
                        }

                    }
                });
        }
    });


}

private void SaveProductInfoToDatabase() {

    HashMap<String,Object> productMap = new HashMap<String,Object>();

    productMap.put("pid",ProductRandomKey);
    productMap.put("date",SaveCurrentDate);
    productMap.put("time",SaveCurrentTime);
    productMap.put("description",Description);
    productMap.put("image",downloadImageUrl);
    productMap.put("category",categoryName);
    productMap.put("price",Price);
    productMap.put("pname",PName);

    ProductRef.child(ProductRandomKey).updateChildren(productMap)
            .addOnCompleteListener(new OnCompleteListener<Void>() {
        @Override
        public void onComplete(@NonNull Task<Void> task) {

            if(task.isSuccessful()){

                loadingBar.dismiss();
                Toast.makeText(AdminAddNewProductActivity.this,"Товар добавлен",Toast.LENGTH_SHORT).show();

                Intent loginIntent = new Intent(AdminAddNewProductActivity.this,AdminCategoryActivity.class);
                startActivity(loginIntent);

            }
            else {
                String message = task.getException().toString();
                Toast.makeText(AdminAddNewProductActivity.this,"Ошибка:" + message,Toast.LENGTH_SHORT).show();
                loadingBar.dismiss();
            }


        }
    });

}

private void Opengallery() {

    Intent galleryIntent = new Intent();
    galleryIntent.setAction(Intent.ACTION_GET_CONTENT);
    galleryIntent.setType("Image/*");
    startActivityForResult(galleryIntent,galLERYPICK);

}

@Override
protected void onActivityResult(int requestCode,int resultCode,@Nullable Intent data) {
    super.onActivityResult(requestCode,resultCode,data);

    if(requestCode== galLERYPICK && resultCode == RESULT_OK && data != null){

        ImageUri = data.getData();
        productimage.setimageURI(ImageUri);

    }
}

private void init() {
    categoryName = getIntent().getExtras().get("category").toString();
    product_name = findViewById(R.id.product_name);
    product_price = findViewById(R.id.product_price);
    product_description = findViewById(R.id.product_description);
    product_price = findViewById(R.id.product_price);
    addNewProductButton = findViewById(R.id.add_new_product);
    ProductimageRef = FirebaseStorage.getInstance().getReference().child("Product Images");
    ProductRef = FirebaseDatabase.getInstance().getReference().child("Products");
    loadingBar = new ProgressDialog(this);
}
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)