我从图库中选择图片时出现错误,该应用突然停止工作。
我已经尝试了几乎所有内容,包括来自firebase的权限和来自Android存储权限的权限,但仍然收到相同的错误。
public class Initial_profile_form extends AppCompatActivity {
EditText username,password;
ImageButton image;
Button insert;
FirebaseDatabase database;
private int Gallery_intent = 2;
FirebaseStorage firebaseStorage;
DatabaseReference ref;
StorageReference storageReferenceProfilePic ,imagePath;
Profile profile;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_initial_profile_form);
username = (EditText) findViewById(R.id.username);
password = (EditText) findViewById(R.id.password);
insert = (Button) findViewById(R.id.button);
image = (ImageButton) findViewById(R.id.imageButton);
database = FirebaseDatabase.getInstance();
firebaseStorage = FirebaseStorage.getInstance();
storageReferenceProfilePic = firebaseStorage.getReference();
ref = FirebaseDatabase.getInstance().getReference("Users");
profile = new Profile();
}
private void getValues(){
profile.setPassword(password.getText().toString());
profile.setUsername(username.getText().toString());
profile.setImageAddress(imagePath.toString());
}
public void btnimage(View view) {
Intent intent = new Intent(Intent.ACTION_PICK);
intent.setType("image/*");
startActivityForResult(intent,Gallery_intent);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(requestCode == Gallery_intent && resultCode == RESULT_OK){
Uri uri = data.getData();
// StorageReference filepath = imagePath.child("Photos").child(uri.getLastPathSegment());
image.setImageURI(uri);
imagePath = storageReferenceProfilePic.child(uri.getLastPathSegment());
//imagePath = FirebaseStorage.getInstance().getReference().child("User").child(uri.getLastPathSegment());
imagePath.putFile(uri).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
Toast.makeText(Initial_profile_form.this,"Uploaded..." , Toast.LENGTH_SHORT);
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Toast.makeText(Initial_profile_form.this,"Not Uploaded..." , Toast.LENGTH_SHORT);
}
});
}
}
public void btnInsert(View view) {
ref.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
getValues();
ref.child("User04").setValue(profile);
Toast.makeText(Initial_profile_form.this, "Data Inserted" , Toast.LENGTH_LONG).show();
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
}
}
E / StorageException:发生StorageException。 发生未知错误,请检查HTTP结果代码和服务器响应的内部异常。 代码:-13000 Http结果:0 发生StorageException。 发生未知错误,请检查HTTP结果代码和服务器响应的内部异常。 代码:-13000 Http结果:0 E / Android运行时:致命例外:FirebaseStorage-Upload-1 流程:com.example.help_pro,PID:22354 java.lang.NoSuchMethodError:没有虚拟方法getToken(Z)Lcom / google / android / gms / tasks / Task;在Lcom / google / firebase / FirebaseApp类中;或其上级类(“ com.google.firebase.FirebaseApp”的声明出现在/data/app/com.example.help_pro-1/split_lib_dependencies_apk.apk中) com.google.android.gms.internal.firebase_storage.zzk.zza上(未知来源) com.google.android.gms.internal.firebase_storage.zzf.zza上(未知来源) 位于com.google.firebase.storage.UploadTask.zzc(未知来源) 位于com.google.firebase.storage.UploadTask.run(未知来源) 位于com.google.firebase.storage.StorageTask.zzl(未知来源) 在com.google.firebase.storage.zzx.run(未知来源) 在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133) 在java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:607) 在java.lang.Thread.run(Thread.java:761)
答案 0 :(得分:0)
检查是否添加了以下库。 实施'com.google.firebase:firebase-storage:17.0.0'