我关闭了防火墙,但问题仍然存在com.android.volley.NetworkError
我也在清单中实现了,但没有实现
public class MainActivity extends AppCompatActivity implements
Response.Listener<JSONObject>, Response.ErrorListener {
//declare variables
Button btnlogin;
TextView tvcreateuser;
private ViewPager screenPager;
RequestQueue rq;
JsonRequest jrq;
EditText cajaUser,cajaPwd;
Button btnConsultar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//start variables
btnlogin = (Button)findViewById(R.id.btnlogin);
tvcreateuser = (TextView)findViewById(R.id.tvcreateuser);
cajaUser = (EditText)findViewById(R.id.txtUser);
cajaPwd =(EditText)findViewById(R.id.txtPwd);
btnConsultar = (Button)findViewById(R.id.btnSesion);
rq = Volley.newRequestQueue(this);
btnConsultar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
iniciarSesion();
}
});
//functions
login();
createuser();
}
private void createuser() {
tvcreateuser.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this,CreateUserActivity.class);
startActivity(intent);
}
});
}
private void login() {
btnlogin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this,PrincipalActivity.class);
startActivity(intent);
}
});
}
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(this, "Nada perrito"+error.toString(), Toast.LENGTH_SHORT).show();
}
@Override
public void onResponse(JSONObject response) {
Toast.makeText(this, "Se encontro el usuario", Toast.LENGTH_SHORT).show();
User usuario = new User();
JSONArray jsonArray = response.optJSONArray("datos");
JSONObject jsonObject = null;
try {
jsonObject = jsonArray.getJSONObject(0);
usuario.setUser(jsonObject.optString("user"));
usuario.setPwd(jsonObject.optString("pwd"));
usuario.setNames(jsonObject.optString("names"));
} catch (JSONException e) {
e.printStackTrace();
}
}
private void iniciarSesion(){
String url = "http://10.62.2.71/login/sesion.php?user="+cajaUser.getText().toString()+
"&pwd="+cajaPwd.getText().toString();
jrq = new JsonObjectRequest(Request.Method.GET,url,null,this,this);
rq.add(jrq);
}
}
我关闭了防火墙,但问题仍然存在com.android.volley.NetworkError
答案 0 :(得分:0)
将此行添加到AndroidManifest.xml
<manifest ....>
<uses-permission android:name="android.permission.INTERNET" />
<application>
....
</manifest>