开发者

IO.Exception in the Logcat but I can see the app running

public class tryget extends Activity
{
    TextView result1;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.mai开发者_如何学Gon);
        Log.i("GET RESPONSE","result outside");
        try
        {
            HttpClient client = new DefaultHttpClient();  
            String getURL = "http://10.0.2.2:8888/mainserver1/androidservlet";
            HttpGet get = new HttpGet(getURL);
            HttpResponse responseGet = client.execute(get);  
            HttpEntity resEntityGet = responseGet.getEntity();  
            if (resEntityGet != null)
            {  
                InputStream is = resEntityGet.getContent();
                String s=is.toString();
                byte[] bytes =s.getBytes();

                ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(bytes));

                String result =  (String) in.readObject();


                result1=(TextView)findViewById(R.id.result1);
                result1.setText(s);
                result1.findViewById(R.id.result1);


                //do something with the response
                //Log.i("GET RESPONSE",EntityUtils.getContentCharSet(resEntityGet));
                Log.i("GET RESPONSE",result);
                // in.close();
                is.close();  
            }
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    }
}

I can see the app running in the emulator but i cant see the text field containing the value for "result" nothing appears in its space and the Logcat shows IO.exception when i run the code with server alive.


You can't see the value for "result" because an exception was thrown before it got to Log.i("GET RESPONSE",result);. Fix the problem described in the Exception thrown, and you will see your result.

Also, instead of writing e.printStackTrace(); in the catch, write something like this:

Log.e("MY TAG", e.toString(), e);

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜