0

I am trying to upload 2 images and this is a class used for that. However, I am getting unreachable statement error.

public class uploadinfo {
    private String imageName;
    private String imageURL;
    private String imageURL2;
    public uploadinfo(){}

    uploadinfo(String name, String url) {
        this.imageName = name;
        this.imageURL = url;
        this.imageURL2 = url;
    }

    public String getImageName() {
        return imageName;
    }
    public String getImageURL() {
        return imageURL;
        return imageURL2;
    }}
Serafins
  • 1,237
  • 1
  • 17
  • 36
  • Hey, I don't understand the intent of your code. why do you have two imageURLs as both of them are initialized by the same ```url``` string. – Ismail Shaikh May 06 '20 at 12:21

2 Answers2

0
    public String getImageURL() {
        return imageURL;
        return imageURL2;
    }

Exeuction of a non-void method ends when a first RETURN statement is encountered, which is return imageURL; in your example. The second return is never executed ( = it is unreachable), because first one returns execution back.

You might split the method into two methods, for example getImageURL() and getImage2URL(), or return the URLs somehow packed (split by a space or any other character of your choice).

0

If you want to return both the imageURLs from the same method then you should use a Pair object. like this -

public Pair<String, String> getImageURL(){
    return new Pair(imageURL, imageURL2);
}
Ismail Shaikh
  • 482
  • 4
  • 13