我已經創建了一個jsonobject,從服務器拉數據,但它只適用於小於3(舊版本)的Android版本。什麼代碼才能在所有版本上運行?使應用程序適用於所有Android版本
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
DefaultHttpClient client;
client = new DefaultHttpClient();
HttpGet get = new HttpGet("http://saurabhgoyal.comoj.com/json_test.php");
HttpResponse r;
try {
r = client.execute(get);
HttpEntity e = r.getEntity();
InputStream is=e.getContent();
InputStreamReader isr=new InputStreamReader(is);
BufferedReader reader=new BufferedReader(isr);
String results=reader.readLine();
Toast.makeText(this, results, Toast.LENGTH_SHORT).show();
} catch (ClientProtocolException e1) {
// TODO Auto-generated catch block
Toast.makeText(this, "failure", Toast.LENGTH_SHORT).show();
e1.printStackTrace();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
例如JSON數組能否請你別說當你在運行3+到底發生了什麼版本?任何錯誤味精或日誌將有所幫助 –
我在我的單元格中嘗試它直接崩潰說不幸它已停止工作。 –
請在應用程序崩潰時打開Logcat並查找錯誤日誌,並在可能的情況下將其粘貼到此處。 –