我收到了这些错误:
07-06 01:04:41.336 1484-1484/quickbook.com.volleyjsonobject W/System.err: com.android.volley.TimeoutError
07-06 01:04:41.336 1484-1484/quickbook.com.volleyjsonobject W/System.err: at com.android.volley.toolbox.BasicNetwork.performRequest(BasicNetwork.java:147)
07-06 01:04:41.336 1484-1484/quickbook.com.volleyjsonobject W/System.err: at com.android.volley.NetworkDispatcher.run(NetworkDispatcher.java:114)
我的代码是:
public class MainActivity extends AppCompatActivity {
Button button;
TextView Name, Email, Mobile;
String json_url = "http://10.0.2.2:8080/getinfo.php";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button = (Button) findViewById(R.id.bn);
Name = (TextView)findViewById(R.id.name);
Email = (TextView) findViewById(R.id.email);
Mobile = (TextView) findViewById(R.id.mobile);
button.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, json_url, (String) null,
new Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try {
Name.setText(response.getString("Name"));
Email.setText(response.getString("Email"));
Mobile.setText(response.getString("Mobile"));
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(MainActivity.this, "something went wrong", Toast.LENGTH_LONG).show();
error.printStackTrace();
}
});
MySingleton.getInstance(MainActivity.this).addToRequestque(jsonObjectRequest);
}
});
}
}
我正试图从本地主机获取一个json对象,但我得到了Volley超时错误。我在graddle.app文件中添加了依赖项。以及清单中的Internet权限。