Saturday, January 25, 2014

httpget Gets a string fails, God help you look great.


            
Follow the example online to do is not to return a string that is needed more time android4.0 networks, can not be written in the main thread, I also opened a thread, or get less, but also add to the authority. Please God help me look great, thank you.

 public class MainActivity extends Activity {

private Button btn1 = null;
private TextView t1 = null;
private final String STRURL = "http://www.google.cn";
@ Override
protected void onCreate (Bundle savedInstanceState) {
super.onCreate (savedInstanceState);
setContentView (R.layout.activity_main);
btn1 = (Button) findViewById (R.id.btn1);
t1 = (TextView) findViewById (R.id.t1);
btn1.setText ("test");
btn1.setOnClickListener (new mylistener ());
}

private Handler myhandler = new Handler ();

private String GetHtmlResult (String c)
{
String ResultString = "";
HttpGet httpGetRequest = new HttpGet (STRURL);
try
{
Log.e ("net", STRURL);
HttpResponse httpResponse = new DefaultHttpClient () execute (httpGetRequest);.
if (httpResponse.getStatusLine (). getStatusCode () == 200)
{
ResultString = EntityUtils.toString (httpResponse.getEntity ());
}
}
catch (Exception ex)
{
ResultString = ex.getMessage ();
}
return ResultString;
}



public class mylistener implements OnClickListener {

@ Override
public void onClick (View arg0) {
MyThread m = new MyThread ();
myhandler.post (m);
}

};

public class MyThread implements Runnable {
@ Override
public void run () {
/ / TODO Auto-generated method stub
t1.setText (GetHtmlResult (STRURL));
}
}
}



Error message

09-21 07:54:06.396: E / SoundPool (287): error loading / system / media / audio / ui / Effect_Tick.ogg
09-21 07:54:06.396: W / AudioService (287): Soundpool could not load file: / system / media / audio / ui / Effect_Tick.ogg
09-21 07:54:06.406: E / SoundPool (287): error loading / system / media / audio / ui / Effect_Tick.ogg
09-21 07:54:06.406: W / AudioService (287): Soundpool could not load file: / system / media / audio / ui / Effect_Tick.ogg
09-21 07:54:06.416: E / SoundPool (287): error loading / system / media / audio / ui / Effect_Tick.ogg
09-21 07:54:06.416: W / AudioService (287): Soundpool could not load file: / system / media / audio / ui / Effect_Tick.ogg
09-21 07:54:06.416: E / SoundPool (287): error loading / system / media / audio / ui / Effect_Tick.ogg
09-21 07:54:06.416: W / AudioService (287): Soundpool could not load file: / system / media / audio / ui / Effect_Tick.ogg
09-21 07:54:06.426: E / SoundPool (287): error loading / system / media / audio / ui / Effect_Tick.ogg
09-21 07:54:06.426: W / AudioService (287): Soundpool could not load file: / system / media / audio / ui / Effect_Tick.ogg
09-21 07:54:06.426: E / SoundPool (287): error loading / system / media / audio / ui / KeypressStandard.ogg
09-21 07:54:06.436: E / net (786): http://www.google.cn
09-21 07:54:06.446: W / AudioService (287): Soundpool could not load file: / system / media / audio / ui / KeypressStandard.ogg
09-21 07:54:06.446: E / SoundPool (287): error loading / system / media / audio / ui / KeypressSpacebar.ogg
09-21 07:54:06.446: W / AudioService (287): Soundpool could not load file: / system / media / audio / ui / KeypressSpacebar.ogg
09-21 07:54:06.456: E / SoundPool (287): error loading / system / media / audio / ui / KeypressDelete.ogg
09-21 07:54:06.456: W / AudioService (287): Soundpool could not load file: / system / media / audio / ui / KeypressDelete.ogg
09-21 07:54:06.456: E / SoundPool (287): error loading / system / media / audio / ui / KeypressReturn.ogg
09-21 07:54:06.466: W / AudioService (287): Soundpool could not load file: / system / media / audio / ui / KeypressReturn.ogg
09-21 07:54:06.476: W / AudioService (287): onLoadSoundEffects (), Error -1 while loading samples
Reply:
log does not seem useful information, what kind of code method returns a value?
Reply:
Html on the page should return it. . . .
Reply:
Top up. God look big trouble.
Reply:
Set breakpoints. . View
Reply:
I have encountered this problem. Top with it.
Reply:
The original version of the problem.
The code on the 2.2 or 2.3 can be executed.
I started the virtual machine is 4.0, and can not use. .

No comments:

Post a Comment