安卓无法在firebase上上载图像,因为拒绝了之前失败的java类上的reinit。类错误
我正试图通过从手机的多媒体资料中选择图像来上传图像。但是在选择它之后,什么都不做,甚至不上传它
我试过干净的建筑和重建,但仍然没有帮助
它只需通过以下方式自动断开连接:
V/FA: Connection attempt already in progress D/FA: Connected to remote service V/FA: Processing queued up service tasks: 2 V/FA: Inactivity, disconnecting from the service
public class MainActivity extends AppCompatActivity {
Button uploadButton;
ImageView downloadedImage;
private static final int CAMERA_REQUEST_CODE=1;
private StorageReference storageReference;
//private ProgressDialog progressDialog;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
uploadButton = findViewById(R.id.button);
downloadedImage = findViewById(R.id.imageView);
storageReference = FirebaseStorage.getInstance().getReference();
//progressDialog = new ProgressDialog(this);
uploadButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(Intent.ACTION_PICK);
intent.setType("image/*");
startActivityForResult(intent,CAMERA_REQUEST_CODE);
Log.i("Done","Till here");
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(requestCode == CAMERA_REQUEST_CODE && requestCode == RESULT_OK)
{
Log.i("Not Done","This log is not visible");
Uri uri = data.getData();
StorageReference filepath = storageReference.child("Photo").child(uri.getLastPathSegment());
filepath.putFile(uri).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
//progressDialog.dismiss();
Toast.makeText(MainActivity.this,"Uploaded...",Toast.LENGTH_LONG).show();
}
});
}
}
}
我得到的错误是:
I/art: Rejecting re-init on previously-failed class java.lang.Class: java.lang.NoClassDefFoundError: Failed resolution of: L安卓/view/View$OnUnhandledKeyEventListener;
# 1 楼答案
在&;之后将requestCode更改为resultCode&;它会起作用的