0
我不明白什麼logcat說,因爲我不是真的老的android開發。 這是logcat。代碼如下..越來越不幸錯誤當試圖使用httpclient和打印整數
public class Json extends Activity {
HttpClient client;
TextView tvStatus;
final static String url = "http://localhost/index.php";
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.json);
tvStatus = (TextView) findViewById(R.id.tvStatus);
client = new DefaultHttpClient();
try {
int data = this.users();
String Data = String.valueOf(data);
tvStatus.setText(Data);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public int users() throws ClientProtocolException, IOException
{
StringBuilder URL = new StringBuilder(url);
HttpGet get = new HttpGet(URL.toString());
HttpResponse r = client.execute(get);
int status = r.getStatusLine().getStatusCode();
return status;
}
}
只是想獲得狀態並追加到tvStatus。問題和解決方案可能是什麼?
請不要讓人關注鏈接。請編輯你的問題並粘貼logcat。 – Simon
@Simon我不能粘貼很多代碼。規則的計算器 –
http://blog.vogella.com/2012/02/22/android-strictmode-networkonmainthreadexception/ – Simon