Android-dev.it Community

 
Annunci

:arrow: Benvenuto!, se non sei ancora un utente registrato: puoi registrati qui, oppure effettua il login
:arrow: Apri un forum sul tuo nuovo smartphone Android e collabora con noi! (dettagli)

www.agendadigitale.org
Image


Sponsor
It is currently Fri May 18, 2012 5:32 pm

All times are UTC + 1 hour


 Topics   Replies   Views   Last post 
No new posts Apri un forum sul tuo nuovo smartphone Android!

[ Go to page: 1, 2, 3 ]

by ReattileGar on Fri May 18, 2012 5:27 pm in Amministrazione

27

12410

Fri May 18, 2012 5:27 pm

ReattileGar

No new posts Новый: базы для хрумера - профессиональный софт для СЕО.

by Renatafe on Fri May 18, 2012 3:14 pm in Amministrazione

0

3

Fri May 18, 2012 3:14 pm

Renatafe

No new posts Pace is undoubtedly the vital affordable Jerseys Wholesale d

by barnettmmolive2012 on Wed May 16, 2012 7:36 am in Amministrazione

1

44

Wed May 16, 2012 7:36 am

barnettmmolive2012

No new posts Problema di compatibilità app

by deran on Tue May 15, 2012 10:44 am in Sviluppo e programmazione in Android

4

186

Tue May 15, 2012 10:44 am

deran

No new posts Applicazione inserimento eventi

by mauro21 on Mon May 14, 2012 9:20 pm in Sviluppo e programmazione in Android

0

23

Mon May 14, 2012 9:20 pm

mauro21




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: BufferedReader ritorna null ad una prima lettura
PostPosted: Fri Sep 16, 2011 2:21 pm 
Offline
User avatar

Joined: Fri Sep 16, 2011 2:09 pm
Posts: 2
Punti Android: ?
Ciao a tutti, sono nuovo del forum. Volevo porvi un problema.
Sto sviluppando un'applicazione, in android naturalmente ;) Nella sezione per fare il login di questa applicazione vi è un bottone, al click viene fatto partire un thread che esegue la seguente funzione: ( i parametri passati sono esatti ):

Code:
   public static String sendData(String data) throws IOException{
      
         StringBuilder sb = null;
         final String charset = "ASCII";
         URLEncoder.encode(data, charset);
         final URL url = new URL("url al quale connettersi");
         URLConnection conn = url.openConnection();
         conn.setDoOutput(true);
         OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
         wr.write(data);
         wr.flush();
         BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
         sb = new StringBuilder();
         String line = null;
         
         while((line = br.readLine()) != null){
            
            sb.append(line);
            
         }
         
         wr.close();
         br.reset();
         br.close();
      
      return sb.toString();
   }


Alla pressione del bottone di Login il valore di ritorno della funzione viene assegnato ad una varibile, la quale poi viene passata al setText di un Toast per essere visualizzata.
Ma solo al secondo ed ai successivi tentativi di login appare effettivamente la stringa che mi interessa. Al primo tentativo ogni volta mi ritorna un null.
Forse leggo dal BufferedReader ancora prima che dall'altra parte sia stato instradato il dato, ma non sono certo di questo. Gradirei molto qualche parare al riguardo, perchè alla fine per funzionare funziona, però mai al primo colpo :? Grazie.


Top
 Profile  
 
 Post subject: Re: BufferedReader ritorna null ad una prima lettura
PostPosted: Sat Sep 24, 2011 3:56 pm 
Offline
Moderatore
User avatar

Joined: Thu Dec 27, 2007 3:51 pm
Posts: 986
Cellulare Android: HTC Dream
Operatore: TIM
Punti Android: 1320
Ciao, credo che la tua supposizione sia esatta: se fai partire un thread forse il problema del NULL la prima volta è dovuto a quello.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
SitemapIndex SitemapIndex RSS Feed RSS Feed Channel list Channel list
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
phpBB SEO

All trademarks and logos used in this site are of properties of their respective owners.