Results 1 to 4 of 4
  1. #1
    JetLagFox is offline Member
    Join Date
    Jan 2017
    Posts
    21
    Rep Power
    0

    Default The code is not entering to a method

    Hi everyone,

    I have a method inside a class that its only task is to download some images to a folder. If I run this code apart in another main class it works, but when I try to implement it to another code it is not entering to the method, or it enters but does nothing.

    Java Code:
                   if (getStatusConnectionCode(urlPage) == 200) {
           				
                        // Obtengo el HTML de la web en un objeto Document2
                        Document document = getHtmlDocument(urlPage);
                        
                        // Busco todas las historias de meneame que estan dentro de: 
                        String entradas = document.select("div.container div#gameDetails h1").text();
           				
    
                        listaEmpresaA[filas][0] = (entradas);
                        System.out.println("Nombre: "+entradas);
                        listaEmpresaA[filas][1] = (all_links.get(i));
                        System.out.println("URL: " + all_links.get(i));
                        String gameImage = entradas;
                                            
                        entradas = document.select("div.grid-11 div.Text p").text();
                        
                        listaEmpresaA[filas][4] = entradas;
                        System.out.println("Descripcion: " + entradas);
           				
                        
                        Elements entrada = document.select("div#MediaControl div#overview1 div img");
                        
                        for (Element enter:entrada) {
                        	String thumb = enter.attr("src");   
                        	
                        	System.out.println("Thumb: "+thumb);
                        	System.out.println("Game Image: "+gameImage);
                    	
                        	gameImage = gameImage.replace(" ", "_")+".jpg";
    
                        	descargar_imagen(thumb, gameImage);
                            
                        	listaEmpresaA[filas][11] = gameImage;
                        	System.out.println("Imagen: "+ gameImage);  
                        	
                        	
                        }
                        
                        String precio = document.select("div.grid-5 span.ProductPrices span").text();
                        listaEmpresaA[filas][8] = entradas;
                        System.out.println("Precio: "+precio);
                        
                        Elements pegi = document.select("div#ProductTitleRating a img");
                        
                        String descripcion_pegi = "";
                        
                        for (Element Pegis : pegi) {
                        	String clase = Pegis.getElementsByAttribute("class").text();
                        	
                        	if (clase.length() == 0) {
                        		descripcion_pegi += Pegis.attr("title")+";";
                        	} else {
                        		String edad_pegi = Pegis.attr("title");
                        		listaEmpresaA[filas][5] = descripcion_pegi;
                                System.out.println("Edad Pegi: "+ edad_pegi);
                        	}
                        	
                        }
                        
                        listaEmpresaA[filas][6] = descripcion_pegi;
                        System.out.println("Descripcion Pegi: "+descripcion_pegi);
                                  
                        
                        filas++;
                  
                        
                    }
    And the method code:

    Java Code:
    public static void descargar_imagen(String link, String nombre) {
           
        
           String url = link;
            
           String name = nombre; //nombre del archivo destino
         
           
           try {
    
           
           //Directorio destino para las descargas
            String folder = "descargas/caratulas_Xbox_360/";
     
            //Crea el directorio de destino en caso de que no exista
            File dir = new File(folder);
     
            if (!dir.exists())
                if (!dir.mkdir())
                return; // no se pudo crear la carpeta de destino
            
            File file = new File(folder + name);
           
            URLConnection conn = new URL(url).openConnection();
            conn.connect();
            System.out.println("\nempezando descarga: \n");
            System.out.println(">> URL: " + url);
            System.out.println(">> Nombre: " + name);
            System.out.println(">> tamaño: " + conn.getContentLength() + " bytes");
            
            InputStream in = conn.getInputStream();
            OutputStream out = new FileOutputStream(file);  
            
            int b = 0;
            while (b != -1) {
                b = in.read();
                if (b != -1)
                out.write(b);
            }
            
            out.close();
            in.close();
            
            } catch (MalformedURLException e) {
                 System.out.println("la url: " + url + " no es valida!");
            } catch (IOException e) {
                e.printStackTrace();
            } 
           
        }
    But is not doing anything. If somebody could give me some tips...

    Thanks in advice.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,001
    Rep Power
    33

    Default Re: The code is not entering to a method

    it is not entering to the method, or it enters but does nothing.
    The descargar_imagen method is called from inside of a loop. Is the loop being executed?
    Can you add some print statements that show the values returned by the methods used and the values in the variables so we can see what the code is doing when it is executing?
    Last edited by Norm; 01-23-2017 at 12:40 PM.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    JetLagFox is offline Member
    Join Date
    Jan 2017
    Posts
    21
    Rep Power
    0

    Default Re: The code is not entering to a method

    Quote Originally Posted by Norm View Post
    The descargar_imagen method is called from inside of a loop. Is the loop being executed?
    Can you add some print statements that show the values returned by the methods used and the values in the variables so we can see what the code is doing when it is executing?
    Yes it enters to the "for" conditional always, for example:

    This is inside the "for" condicional where I am calling the method.

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,001
    Rep Power
    33

    Default Re: The code is not entering to a method

    If the execution enters the for loop then it has to call the method.
    What happens inside of the method? What are the values of the variables used inside of the method?
    Can you add print statements to the method to show what it is doing?

    Please copy the text of what is print and paste it here so we can see. No images.
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. Problem with entering data
    By Jey in forum JDBC
    Replies: 7
    Last Post: 10-10-2011, 02:42 PM
  2. Replies: 0
    Last Post: 08-07-2011, 08:32 PM
  3. entering textfile into database
    By UJJAL DHAR in forum New To Java
    Replies: 11
    Last Post: 06-15-2010, 01:55 AM
  4. Entering string in a loop with method
    By Konex in forum New To Java
    Replies: 3
    Last Post: 03-01-2009, 07:33 AM
  5. How to stop entering Data
    By adeeb in forum AWT / Swing
    Replies: 1
    Last Post: 06-07-2008, 02:58 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •