以下のコードでは、Android プロジェクトの実行時にエラーが発生します
コード:
try {
Gson gson = new Gson();
String json = gson.toJson(stockDetailData);
String json1 = gson.toJson(stockMainData);
String json2 = gson.toJson(pledgerData);
JSONObject jo = new JSONObject();
jo.put("stockDetailData", json.toString());
jo.put("stockMainData", json1.toString());
jo.put("pledgerData", json2.toString());
jo.put("company_id", "4");
URL url = new URL("http://127.0.0.1:180/AfaqTraders/index.php/sale/saveVoucher");
HttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url.toURI());
// Prepare JSON to send by setting the entity
httpPost.setEntity(new StringEntity(jo.toString(), "UTF-8"));
// Set up the header types needed to properly transfer JSON
httpPost.setHeader("Content-Type", "application/json");
httpPost.setHeader("Accept-Encoding", "application/json");
httpPost.setHeader("Accept-Language", "en-US");
// Execute POST
HttpResponse response = httpClient.execute(httpPost);
} catch(Exception e) {
Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_LONG).show();
}
エラー: android.os.NetworkOnMainThreadException
エラーを探していますが、見つかりません。ここで私が間違っていることを誰か教えてもらえますか??