java.io.IOException: Could not open

0

These are the errors that happen to me and what I do, a reader and I try to pass it to a parsing, what I do is send a data and return the string in XML and thus pass it in Sax.

    <?php 
$link = mysqli_connect("mysql.hostinger.es", "u126083979_admin", "123456", "u126083979_lugar"); 
     if(isset($_POST['nombre'])) 
     { 
      $nombre = $_POST['nombre']; 
      $query1 = "SELECT * FROM Sitio WHERE Nombre = $nombre"; 
       if($result = mysqli_query($link, $query1)) 
       { 
             echo "<Sitios>"; 
             while($Sitio = mysqli_fetch_array($result)) 
             { 
              echo "<Sitio>"; 
              echo "<Nombre>" . $Sitio['Nombre'] . "</Nombre>"; 
            echo "<ImagenPrin>" . $Sitio['ImagenPrin'] . "</ImagenPrin>"; 
              echo "</Sitio>"; 
             } 
             echo "</Sitios>"; 
             mysqli_free_result($result); 

       } 
       else 
       { 
         echo "ERROR: $sql. " . mysqli_error($link); 
       } 
     } 
?>

Any ideas on how to fix it

04-18 18:04:45.530 12331-20851/com.adilosa94.theturistllion W/System.err: java.io.IOException: Couldn't open <Sitios><Sitio><Nombre>Basílica de San Isidoro</Nombre><ImagenPrin>http://theturistllion.hol.es/upload/Imagenes/Sitios%20Principal/san_isidoro.jpg</ImagenPrin></Sitio></Sitios>
    04-18 18:04:45.533 12331-20851/com.adilosa94.theturistllion W/System.err: Caused by: java.net.MalformedURLException: Protocol not found: <Sitios><Sitio><Nombre>Basílica de San Isidoro</Nombre><ImagenPrin>http://theturistllion.hol.es/upload/Imagenes/Sitios%20Principal/san_isidoro.jpg</ImagenPrin></Sitio></Sitios>

try {

                int response_code = conexion.getResponseCode();

                if (response_code == HttpURLConnection.HTTP_OK) {
                    // Lee los datos enviados desde el php
                    InputStream input = conexion.getInputStream();
                    BufferedReader reader = new BufferedReader(new InputStreamReader(input));
                    StringBuilder result = new StringBuilder();
                    String line;
                    System.out.print("TODO BIEN");
                    while ((line = reader.readLine()) != null) {
                        result.append(line);
                        SAXParserFactory factory = SAXParserFactory.newInstance();
                        SAXParser parser = factory.newSAXParser();
                        SaxHandlerSitio handler = new SaxHandlerSitio();
                        parser.parse(line, handler);

                    }

                    return (result.toString());
                } else {
                    return ("suceso");
                }

            } catch (IOException e) {
                e.printStackTrace();
                return "exception";
            } catch (ParserConfigurationException e) {
               e.printStackTrace();
           } catch (SAXException e) {
               e.printStackTrace();
           } finally {
                conexion.disconnect();
            }
            return null;

This is my class deparseo by sax handler

'
public class SaxHandlerSitio extends DefaultHandler{
    private List<Sitio> sitios;
    private Sitio sitioAc;
    private StringBuilder sbText;
    public Boolean parsingError = false;



    public List<Sitio> getSitios(){
        return sitios;
    }


    @Override
    public void startDocument() throws SAXException {

        super.startDocument();

        sitios = new ArrayList<Sitio>();
        sbText = new StringBuilder();
    }

    @Override
    public void startElement(String uri, String localName, String name, Attributes attributes) throws SAXException {

        super.startElement(uri, localName, name, attributes);

        if (localName.equals("Sitio")) {
            sitioAc = new Sitio(name, 0,0);
        }
    }

    @Override
    public void characters(char[] ch, int start, int length)
            throws SAXException {

        super.characters(ch, start, length);

        if (this.sitioAc != null)
            sbText.append(ch, start, length);
    }


    @Override
    public void endElement(String uri, String localName, String name)
            throws SAXException {

        super.endElement(uri, localName, name);
        double value;
        int valor = 0;
        if (this.sitioAc != null) {

            if (localName.equals("Nombre")) {
                sitioAc.setNombre(sbText.toString().trim());
            }
            else if (localName.equals("Latitud")) {
                value = Double.parseDouble(sbText.toString().trim());
                sitioAc.setLatitud(value);
            }
            else if (localName.equals("Longitud")) {
                value = Double.parseDouble(sbText.toString().trim());
                sitioAc.setLongitud(value);
            }
            else if (localName.equals("ImagenPrin")) {
                sitioAc.setImagen(sbText.toString().trim());
            }
            else if (localName.equals("Sitio")) {
                sitios.add(sitioAc);
            }
            sbText.setLength(0);
        }
    }

}'
    
asked by Alejandro Díez 18.04.2017 в 18:11
source

1 answer

0

The problem is:

 Caused by: java.net.MalformedURLException: Protocol not found:
 <Sitios><Sitio><Nombre>Basílica de San
 Isidoro</Nombre><ImagenPrin>http://theturistllion.hol.es/upload/Imagenes/Sitios%20Principal/san_isidoro.jpg</ImagenPrin></Sitio></Sitios>

MalformedURLException , What should be a url, in reality is a string of characters that can not be represented as Url since it does not start with the protocol http:// ,

<ImagenPrin>http://theturistllion.hol.es/upload/Imagenes/Sitios%20Principal/san_isidoro.jpg</ImagenPrin></Sitio></Sitios>

should be only:

http://theturistllion.hol.es/upload/Imagenes/Sitios%20Principal/san_isidoro.jpg

You have to ensure the parser will only get the URL to make the connection!.

You may need to change your .php page in this way, to get only the url:

  if($result = mysqli_query($link, $query1)) 
       { 
            // echo "<Sitios>"; 
             while($Sitio = mysqli_fetch_array($result)) 
             { 
            //  echo "<Sitio>"; 
              //echo "<Nombre>" . $Sitio['Nombre'] . "</Nombre>"; 
              //echo "<ImagenPrin>" . $Sitio['ImagenPrin'] . "</ImagenPrin>"; 
              echo . $Sitio['ImagenPrin']; 
             // echo "</Sitio>"; 
             } 
            // echo "</Sitios>"; 
             mysqli_free_result($result); 

       } 
    
answered by 18.04.2017 / 18:25
source