I cannot get the image URL from a JSON file, although it is done in the same way as other data that is obtained correctly

Asked

Viewed 143 times

0

I’m developing an app based on another app, in case the app is a map (provided by Google Maps Apis) where points are added map and can be clicked to display more information about the location, this data (name, description and geographical coordinates) are obtained from a JSON file.

A video to better elucidate the operation of the application: https://www.youtube.com/watch?v=1z2oIMFM5ZM

So, I would like that Imageview where that GTA V image appears (used only for example) to be obtained through a URL obtained from a JSON file, as well as the data cited above. The JSON file in question is this: https://api.myjson.com/bins/ox334

(In the following codes, it is possible to see my failure to attempt to imitate the codes that correctly obtained the data (such as name, description and coordinates) in the source code I used as a basis, but I could not and could not identify the correct cause of the problem let alone fix it...)

RESULTS OBTAINED BY DEBUGGING THE APPLICATION: https://imgur.com/a/H2k0CBL inserir a descrição da imagem aqui

After seeing the above images, notice that in the code of the file Points.java, "receive Image" is the only one that does not return anything when a breakpoint is added to it and run in debugging, until the "Image application" itself returns the URL that exists there in JSON, but I noticed something strange in this that can be seen in the images above, after the line of "application" in Points.java, breakpoint returns at the end the warning "image: null", which is strange, since it does not appear in other lines which I added breakpoints to debug.

After all I really don’t know what the cause of the problem is.

OBS. Includes relevant parts of the code below, along with links to such complete Java files for reading in Pastebin.

Outraactivity.java (A Activity where the image should appear in Imageview "Imagemlugar"): (Outraactivity.java complete: https://pastebin.com/kwyv9EeY)

    private ImageView ImagemLugar;
      ...
    public static ArrayList<Pontos> iwantimage = new ArrayList<>();
       ...
    ImagemLugar = (ImageView) v.findViewById(R.id.imageem);
    setHasOptionsMenu(true);

     for (int i = 0; i < iwantimage.size(); i++) {
         Pontos pontos = iwantimage.get(i);

         Picasso.get().load(pontos.recebeImagem()).into(ImagemLugar);
    }
    return v;
}

Activity where data is obtained from JSON: (the complete file: https://pastebin.com/eBZq0nDZ)

String url = "https://api.myjson.com/bins/ox334";
  ...
        @Override
    protected String doInBackground(String... params) {
        OkHttpClient client = new OkHttpClient();
        Request request = new Request.Builder().url(url).build();

        ...
            JSONObject objectp = new JSONObject(s);
            JSONArray jArrPoints = objectp.getJSONArray("pontos");

            for (int i =0 ;i<jArrPoints.length();i++) {
                pontos = new Pontos();
                pontos.aplicaNome(jArrPoints.getJSONObject(i).getString("nome"));
                pontos.aplicaPosx(jArrPoints.getJSONObject(i).getString("posx"));
                pontos.aplicaPosy(jArrPoints.getJSONObject(i).getString("posy"));
                pontos.aplicaDescricao( jArrPoints.getJSONObject(i).getString("descricao"));
                pontos.aplicaTipo( jArrPoints.getJSONObject(i).getString("tipo"));
                pontos.aplicaImagem( jArrPoints.getJSONObject(i).getString("imagem"));
                listaitensPontos.add(pontos);
            }
        AbaMapa.listaitens = listaitensPontos;

The file "Points.java", an Arraylist: (Full Java Dots.: https://pastebin.com/mVvgWKgm)

public class Pontos {
    private String nome;
    private String posx;
    private String posy;
    private String descricao;
    private String tipo;
    private String imagem;

    public Pontos(){}
    public Pontos(String nome, String posx, String posy, String descricao, String tipo){
        this.nome = nome;
        this.posx = posx;
        this.posy = posy;
        this.descricao = descricao;
        this.tipo = tipo;
        this.imagem = imagem;

    }
    public String recebeNome() {
        return nome;
    }

    public void aplicaNome(String nome) {
        this.nome = nome;
    }

    public String recebePosx() {
        return posx;
    }

    public void aplicaPosx (String posx) {
        this.posx = posx;
    }

    public String recebePosy() {
        return posy;
    }

    public void aplicaPosy (String posy) {
        this.posy = posy;
    }

    public String recebeDescricao() {
        return descricao;
    }

    public void aplicaDescricao (String descricao) {
        this.descricao = descricao;
    }

    public String recebeTipo() {
        return tipo;
    }

    public void aplicaTipo (String tipo) {
        this.tipo = tipo;
    }

    public String recebeImagem() {
        return imagem;
    }

    public void aplicaImagem (String imagem) {
        this.imagem = imagem;
    }
}
  • At line 83 of the Outraactivity.java file, you create an object without declaring a name, it should look like this Image location = (Imageview) v.findViewById(R.id.imageem); E check that the element ID in the layout is actually picture

  • @J.PedroA., this generates an error when compiling: "error: cannot find Symbol class Imagemlugar"

  • @J.PedroA., besides that "Imagemlugar" in this line ends up with a red marking that details the following: "Unknown Class: 'image'"

  • @J.PedroA., if I had to bet, I would say that the problem is in Points.java This is what comes back to me when I add a breakpoint in the line of the "applicationImage" in Points.java: https://i.imgur.com/7SPv8jw.png

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.