Hammad
Hammad

Reputation: 11

StorageException while uploading image to Firebase

I am getting error when i select picture from gallery the app suddenly stop working.

I have tried almost everything including permissions from firebase and from Android storage permissions still getting same error.

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 has occurred. An unknown error occurred, please check the HTTP result code and inner exception for server response. Code: -13000 HttpResult: 0 StorageException has occurred. An unknown error occurred, please check the HTTP result code and inner exception for server response. Code: -13000 HttpResult: 0 E/AndroidRuntime: FATAL EXCEPTION: FirebaseStorage-Upload-1 Process: com.example.help_pro, PID: 22354 java.lang.NoSuchMethodError: No virtual method getToken(Z)Lcom/google/android/gms/tasks/Task; in class Lcom/google/firebase/FirebaseApp; or its super classes (declaration of 'com.google.firebase.FirebaseApp' appears in /data/app/com.example.help_pro-1/split_lib_dependencies_apk.apk) at com.google.android.gms.internal.firebase_storage.zzk.zza(Unknown Source) at com.google.android.gms.internal.firebase_storage.zzf.zza(Unknown Source) at com.google.firebase.storage.UploadTask.zzc(Unknown Source) at com.google.firebase.storage.UploadTask.run(Unknown Source) at com.google.firebase.storage.StorageTask.zzl(Unknown Source) at com.google.firebase.storage.zzx.run(Unknown Source) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607) at java.lang.Thread.run(Thread.java:761)

Upvotes: 1

Views: 1757

Answers (1)

user3148900
user3148900

Reputation: 21

Check Whether the following library added or not . implementation 'com.google.firebase:firebase-storage:17.0.0'

Upvotes: 2

Related Questions