Je suis nouveau à android et je veux me connecter aux fichiers json, mais quand j'essaye ce code, mais il ne se connecte pas, et quand je l'exécute dans mon téléphone quand je veux travailler, il obtient moi nooo dans logcat selon que j'ai dit de le faire quand il a un problème de connexion au serveur, merciconnexion au serveur avec android
public class LastFMHelper {
public static final String LastFMMetroTrackChartUrl=
"http://ws.audioscrobbler.com/2.0/?method=geo.getmetrotrackchart&country=united+states&metro=denver&format=json&api_key=bc8ae5008414312b31e8c23f684d67cc";
private static final int HTTP_STATUS_OK = 200;
private static byte[] buff = new byte[1024];
private static final String logTag="LastFMHelper";
public static class ApiException extends Exception
{
private static final long serialVersionUID= 1L;
public ApiException (String msg)
{
super(msg);
}
public ApiException(String msg, Throwable thr)
{
super(msg, thr);
}
}
protected static synchronized String downlaodFromServer (String ...params) throws ApiException {
String retval= null;
String metro = params[0];
String url= LastFMMetroTrackChartUrl + "&metro" +metro;
Log.d(logTag,"Fetching"+url);
HttpClient client= new DefaultHttpClient();
HttpGet request = new HttpGet(url);
try{
HttpResponse responce = client.execute(request);
StatusLine status = responce.getStatusLine();
if(status.getStatusCode()!=HTTP_STATUS_OK)
{
throw new ApiException("Invalid responce from last.fm"+status.toString());
}
HttpEntity entity = responce.getEntity();
InputStream ist = entity.getContent();
ByteArrayOutputStream content = new ByteArrayOutputStream();
int readcount =0;
while((readcount= ist.read(buff)) != -1)
{
content.write(buff,0,readcount);
}
retval= new String (content.toByteArray());
}catch(Exception e){
Log.d(logTag,"noo!!");
throw new ApiException("problem connecting to server " + e.getMessage(),e);
}
return retval;
}
}
ce que fait l'impression ApiException dans le journal? s'il n'y a rien, essayez de consigner l'exception et de publier le journal. par exemple, au lieu de 'Log.d (logTag," noo !! ");' essayer 'Log.d (logTag, e.getMessage());' – katzenhut
Je fais qu'il a dit 05-25 12: 14: 37.882 : D/LastFMHelper (22953): Autorisation refusée (permission INTERNET manquante?) – amirhtk