java - Android, get text from url works fine in eclipse but not on device -


as title suggests code works fine in eclipse, export , try use on device doesn't bring down , returns null.

it supposed read text url , display in text view

i have no idea i'm doing wrong, simple cant see it

public class nextevent extends activity implements onclicklistener {  string event; textview eventtext; textview titletext;  string html;  public void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.newevent);      titletext = (textview) findviewbyid(r.id.title);     eventtext = (textview) findviewbyid(r.id.event);                try {              gethtml();         } catch (exception e) {             e.printstacktrace();         }                    eventtext.settext("" + html);     }   private void gethtml() throws clientprotocolexception, ioexception   {     httpclient httpclient = new defaulthttpclient();     httpcontext localcontext = new basichttpcontext();     httpget httpget = new httpget("http://masterzangetsu.eu/apps/rocksoctest"); //url!     httpresponse response = httpclient.execute(httpget, localcontext);     string result = "";      bufferedreader reader = new bufferedreader(new inputstreamreader(response.getentity().getcontent()));      string line = null;     while ((line = reader.readline()) != null) {         result += line + "\n";         html = result;     }  }   public void onclick(view v) {     // todo auto-generated method stub   } 

and heres xml

<?xml version="1.0" encoding="utf-8"?> <scrollview xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/scroller" android:layout_width="fill_parent" android:layout_height="fill_parent" android:fillviewport="true" >  <relativelayout     android:layout_width="fill_parent"     android:layout_height="wrap_content"     android:orientation="vertical" >      <textview         android:id="@+id/title"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_alignparenttop="true"         android:layout_centerhorizontal="true"         android:text="upcoming events"         android:textappearance="?android:attr/textappearancelarge" />      <textview         android:id="@+id/event"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_below="@+id/title"         android:layout_centerhorizontal="true"         android:layout_margintop="44dp"         android:text="sever event update failed" />  </relativelayout>  </scrollview> 

any great

your emulator running older version of android device , you're executing networking call on ui thread inside of try-catch block hiding error ;) older emulator work fine. device not allow that. use asynctask{} make network call.

to illustrate point rid of e.printstacktrace() , put log.e() in there dumps logcat.


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -