Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
YF-23
Feb 17, 2011

My god, it's full of cat!


I have an issue with parsing text from a webpage. I have a function which reads the contents of a webpage and parses it into a String. I have tested the function in a Java console application and it works fine, so if I do
Java code:
String str = DownloadText("http://pastebin.com/raw.php?i=8aG1dVyS");
System.out.print(str);
it will correctly print on the console "sample text", the contents of the page in this example.

On Android however, doing
Java code:
String str = DownloadText("http://pastebin.com/raw.php?i=8aG1dVyS");
		TextView testview = new TextView(this);
		testview.setText(str);
		ll.addView(testview);
will produce an empty space in the position of the TextView. The issue is not with the TextView itself, as other TextViews work fine, and if I replace setText(str) with setText("stuff") then the given String will be properly displayed. The project's manifest.xml does contain the permission to hook up on the Internet (<uses-permission android:name="android.permission.INTERNET" />).

I have no idea why this is not working and it's quite a roadblock. I really don't have any prior experience to developing on Android so it's very likely I'm missing something that ought to be obvious, but I haven't had any luck in figuring out or finding what is causing the application not to parse, or at least return or display the text from the page.

Adbot
ADBOT LOVES YOU

YF-23
Feb 17, 2011

My god, it's full of cat!


That might be it, but in that case this should give me the string I put in the catch block, right?

Java code:
String str = "blah";		
try {str = DownloadText("http://pastebin.com/raw.php?i=ZvBPhbEA");}
catch (NetworkOnMainThreadException e){str = "Network on main thread exception!";}
TextView testview = new TextView(this);
testview.setText(str);
ll.addView(testview);
Because in the end it still comes up blank.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply