Android模拟器应用程序将无法连接到我的本地mysql服务器

时间:2020-05-08 19:01:17

标签: php android json gson android-volley

    // URL
    private final static String base_URL = "http://10.0.2.2:8080/shreemant/fetch_product.php";
    RequestQueue queue;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.delivery);

        final TextView txtName = (TextView)findViewById(R.id.txtName);
        final TextView txtAddress = (TextView)findViewById(R.id.txtAddress);

        queue = Volley.newRequestQueue(this);
        JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, base_URL, null,
                new Response.Listener<JSONObject>() {
                    @Override
                    public void onResponse(JSONObject response) {
                        try {
                            txtName.setText(response.getString("NAME"));
                            txtAddress.setText(response.getString("ADDRESS"));
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                VolleyLog.d("error", error.toString());
            }
        });
        queue.add(request);

在野生动物园中键入相同的URL将显示一个JSON结构,正如我的php脚本所回显的那样。无法弄清楚为什么它不能在Android Studio上运行。还尝试了Gson的方式,得到了error parsing TSL header。错误 真的很感谢您的帮助。

这是Web浏览器中的输出:

{"ORDER_NO":"1","NAME":"PRITESH GOYAL","PHONE":"9893291225","ADDRESS":"CHOTI GWALTOLI","ORDER_DESC":"COW GHEE - 1 KG - QT -1","AMOUNT":"500","DRIVER":"VINOD","LANDMARK":"PATEL BRIDGE"}

0 个答案:

没有答案