Click here to Skip to main content
14,330,512 members
Rate this:
Please Sign up or sign in to vote.
See more:
I get the error when I compile the app. It says that
task.getResult().getDownloadUrl().toString() cannot find the symbol
filePath.putFile(fileUri).addOnCompleteListener(task -> {
         if (task.isSuccessful()){
                        Map messageTextBody = new HashMap();
                        messageTextBody.put("message", task.getResult().getDownloadUrl().toString());
                        messageTextBody.put("name", fileUri.getLastPathSegment());
                        messageTextBody.put("type", checker);
                        messageTextBody.put("from", messageSenderID);
                        messageTextBody.put("to", messageReceiverID);
                        messageTextBody.put("messageID", messagePushID);
                        messageTextBody.put("time", saveCurrentTime);
                        messageTextBody.put("date", saveCurrentDate);
                        Map messageBodyDetails = new HashMap();
                        messageBodyDetails.put(messageSenderRef + "/" + messagePushID, messageTextBody);
                        messageBodyDetails.put(messageReceiverRef + "/" + messagePushID, messageTextBody);
                        RootRef.updateChildren(messageBodyDetails);
                        loadingBar.dismiss();
                    }
                }).addOnFailureListener(new OnFailureListener() {
                    @Override
                    public void onFailure(@NonNull Exception e) {
                        loadingBar.dismiss();
                        Toast.makeText(ChatActivity.this, e.getMessage(), Toast.LENGTH_SHORT).show();
                    }
                }).addOnProgressListener(new OnProgressListener<UploadTask.TaskSnapshot>() {
                    @Override
                    public void onProgress(UploadTask.TaskSnapshot taskSnapshot) {
                        double p = (100.0*taskSnapshot.getBytesTransferred()) / taskSnapshot.getTotalByteCount();
                        loadingBar.setMessage((int) p + " % Uploading...");
                    }
                });


What I have tried:

tried to use this code
filePath.putFile(fileUri).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
                    @Override
                    public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
                        filePath.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
                            @Override
                            public void onSuccess(Uri uri) {
                                String downloadUrl = uri.toString();

                                Map messageImageBody = new HashMap();
                                messageImageBody.put("message", taskSnapshot.getStorage().getDownloadUrl());
                                messageImageBody.put("name",fileUri.getLastPathSegment());
                                messageImageBody.put("type",checker);
                                messageImageBody.put("from",messageSenderID);
                                messageImageBody.put("to", messageReceiverID);
                                messageImageBody.put("messageID", messagePushID);
                                messageImageBody.put("time", saveCurrentTime);
                                messageImageBody.put("date", saveCurrentDate);


                                Map messageBodyDetail = new HashMap();
                                messageBodyDetail.put(messageSenderRef+ "/" + messagePushID, messageImageBody);
                                messageBodyDetail.put(messageReceiverRef+ "/" + messagePushID, messageImageBody);

                                RootRef.updateChildren(messageBodyDetail);
                                loadingBar.dismiss();

                            }
                        }).addOnFailureListener(new OnFailureListener() {
                            @Override
                            public void onFailure(@NonNull Exception e) {
                                loadingBar.dismiss();
                                Toast.makeText(ChatActivity.this, e.getMessage(), Toast.LENGTH_SHORT).show();
                            }
                        });
                    }
                }).addOnProgressListener(new OnProgressListener<UploadTask.TaskSnapshot>() {
                    @Override
                    public void onProgress(UploadTask.TaskSnapshot taskSnapshot) {
                        double p = (100.0* taskSnapshot.getBytesTransferred()) / taskSnapshot.getTotalByteCount();
                        loadingBar.setMessage((int) p + " % Uploading...");
                    }
                });


but the app gets crash on clicking on the file here is the app source code link Chat
Posted
Comments
Richard MacCutchan 5-Oct-19 4:52am
   
You need to use the debugger to find out which item it cannot find.
Tiger Prajapati 5-Oct-19 6:33am
   
well I forget to mention in the answer that im new in android and as I resolve some of the problems, still there are many problems, there which I can't solve it for example if I upload an image or some kind of document in the chat section with single person chat then it shows 2 times in the chat and when I close the chat and reopen the chat then it shows single time only. also the receiver is not able to open the document file.
Richard MacCutchan 5-Oct-19 6:42am
   
That is why you need to use the debugger. Take each problem in turn and try to find out why it is happening. Often it will be connected to the data that your application is trying to process; it may be invalid, or your code assumes a certain format etc. But only you can do this as only you have the data to pass through the code. It is all part of learning to be a developer. Writing code is easy, making it work correctly is often the hard part.
ZurdoDev 7-Oct-19 8:17am
   
As Richard said, for these kinds of problems you need to use the debugger to see why things behave the way they do. But we can't see what you are doing so there is nothing we can do to help.

And statements like "receiver is not able to open the document file" does not mean anything to anyone else. You need to debug and then provide details.
ZurdoDev 7-Oct-19 8:16am
   
OP says the error happens when they compile which means the debugger won't help. Debugger isn't running yet during compilation.
Richard MacCutchan 7-Oct-19 8:36am
   
And the final sentence says the app crashes when clicking on the file. Like so many developers he does not understand where compilation ends and application starts.
ZurdoDev 7-Oct-19 8:44am
   
True.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100