Hello, I'm having a problem I can not understand why that is not working 
the way I want ....

My php file (emailExists.php):


<?php

    $user = "";

    if <http://www.php.net/if>(isset($_GET['email']))
        $user =$_GET['email'];
                
    $conexao = mysql_connect <http://www.php.net/mysql_connect>('localhost'
, 'root', '');
    mysql_select_db <http://www.php.net/mysql_select_db>('android', $conexao
);
        
    $sql = "select * from `users` where email = \"$user\"";
    $resultado = mysql_query <http://www.php.net/mysql_query>($sql) or die 
("Erro 
:" . mysql_error <http://www.php.net/mysql_error>()); 
    $numLinhas = mysql_num_rows <http://www.php.net/mysql_num_rows>(
$resultado);
          
    if <http://www.php.net/if>($numLinhas > 0)
        echo <http://www.php.net/echo> "1";
    else <http://www.php.net/else>
         echo <http://www.php.net/echo> "0";  
              
    mysql_close <http://www.php.net/mysql_close>($conexao);

?>
 



With Apache and MySql assets, can seamlessly access the database via php 
file by typing "http://localhost/android/emailExists.php"; in the browser of 
the machine and even the android emulator browser by typing "http://10.0. 
2.2/android/emailExists.php. "


In the android....

The class code responsible for getting the response from the php file :


public class ConnectionHttpCliente {
    
    private int HTTP_TIMEOUT;
    private HttpClient httpClient;
    
    
    
    
    
    
    public ConnectionHttpCliente(int timeout){
        
        setTimeOut(timeout);
        
        httpClient = new DefaultHttpClient();
        
        HttpParams httpParams = httpClient.getParams();
        HttpConnectionParams.setConnectionTimeout(httpParams, HTTP_TIMEOUT);
        HttpConnectionParams.setSoTimeout(httpParams, HTTP_TIMEOUT);
        ConnManagerParams.setTimeout(httpParams, HTTP_TIMEOUT);          

        
    }


    public 
String<http://www.google.com/search?hl=en&q=allinurl%3AString+java.sun.com&btnI=I%27m%20Feeling%20Lucky>
 
executeHttpGet(String<http://www.google.com/search?hl=en&q=allinurl%3AString+java.sun.com&btnI=I%27m%20Feeling%20Lucky>
 url) throws 
Exception<http://www.google.com/search?hl=en&q=allinurl%3AException+java.sun.com&btnI=I%27m%20Feeling%20Lucky>
{

        
BufferedReader<http://www.google.com/search?hl=en&q=allinurl%3ABufferedReader+java.sun.com&btnI=I%27m%20Feeling%20Lucky>
 buffer 
= null;
    
        try{
            
            HttpGet httpGet = new HttpGet(url);
            
            httpGet.setURI(new URI(url));
            
            HttpResponse httpResponse = httpClient.execute(httpGet);
            
            buffer = new 
BufferedReader<http://www.google.com/search?hl=en&q=allinurl%3ABufferedReader+java.sun.com&btnI=I%27m%20Feeling%20Lucky>
(new 
InputStreamReader<http://www.google.com/search?hl=en&q=allinurl%3AInputStreamReader+java.sun.com&btnI=I%27m%20Feeling%20Lucky>
(httpResponse.getEntity().getContent()));
            
            
StringBuffer<http://www.google.com/search?hl=en&q=allinurl%3AStringBuffer+java.sun.com&btnI=I%27m%20Feeling%20Lucky>
 stringBuffer 
= new 
StringBuffer<http://www.google.com/search?hl=en&q=allinurl%3AStringBuffer+java.sun.com&btnI=I%27m%20Feeling%20Lucky>
("");
            
String<http://www.google.com/search?hl=en&q=allinurl%3AString+java.sun.com&btnI=I%27m%20Feeling%20Lucky>
 line 
= "";
            
String<http://www.google.com/search?hl=en&q=allinurl%3AString+java.sun.com&btnI=I%27m%20Feeling%20Lucky>
 LS 
= 
System<http://www.google.com/search?hl=en&q=allinurl%3ASystem+java.sun.com&btnI=I%27m%20Feeling%20Lucky>
.getProperty("line.separator");
            
            while((line = buffer.readLine()) != null)
                stringBuffer.append(line + LS);
            
            buffer.close();
        
            
String<http://www.google.com/search?hl=en&q=allinurl%3AString+java.sun.com&btnI=I%27m%20Feeling%20Lucky>
 result 
= stringBuffer.toString();
            
            return result;
        
        }finally{
            if(buffer != null){
                
                try{
                    buffer.close();
                
}catch(IOException<http://www.google.com/search?hl=en&q=allinurl%3AIOException+java.sun.com&btnI=I%27m%20Feeling%20Lucky>
 erro){
                    Log.i("Fail", "Error: " + erro.getMessage());
                }
            }

        }

    }
    
    
    
    
    public int getTimeOut(){
        return HTTP_TIMEOUT;
    }
    
    public void setTimeOut(int timeout){
        HTTP_TIMEOUT = timeout * 1000;
    }
    
    
        
}

 





And the method that checks the response :


    public static int 
emailExists(String<http://www.google.com/search?hl=en&q=allinurl%3AString+java.sun.com&btnI=I%27m%20Feeling%20Lucky>
 email){
          
          int result;
          
          
String<http://www.google.com/search?hl=en&q=allinurl%3AString+java.sun.com&btnI=I%27m%20Feeling%20Lucky>
 urlGet 
= "http://10.0.2.2/android/emailExists.php?email="; + edtEmail.getText().
toString();

          
String<http://www.google.com/search?hl=en&q=allinurl%3AString+java.sun.com&btnI=I%27m%20Feeling%20Lucky>
 response 
= null;
          
          try{
              response = new ConnectionHttpCliente(30).executeHttpGet(urlGet
);
                  
              
String<http://www.google.com/search?hl=en&q=allinurl%3AString+java.sun.com&btnI=I%27m%20Feeling%20Lucky>
 responseStr 
= response.toString();
              responseStr = responseStr.replaceAll("\\s+", "");
              
              if(responseStr.equals("1"))
                  result = 1;
              else
                  result = 0;

              
          
}catch(Exception<http://www.google.com/search?hl=en&q=allinurl%3AException+java.sun.com&btnI=I%27m%20Feeling%20Lucky>
 e){
              
              Log.i("Fail", "Error: " + e.getMessage());
              
              result = -1;
              
          }
          
          return result;
      }

 




The above method ALWAYS returns -1 with the error message "NULL". Making a 
simple scan I realized that this error comes from the line:

HttpResponse httpResponse = httpClient.execute(httpGet);




Could anyone help me with this error and how to solve this?



Notes: The MANIFEST file already has the following permissions:

<uses-permission android:name="android.permission.INTERNET" /> 
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to