java - Android Volley: BasicNetwork.performRequest: Unexpected response code 404 -


i want user's information database , display it, keep getting error:

basicnetwork.performrequest: unexpected response code 404

here's javacode:

loading method:

public void loaduserprofile() {      response.listener<string> responselistener = new response.listener<string>() {         @override         public void onresponse(string response) {             try {                 jsonobject jsonresponse = new jsonobject(response);                 idtv.settext(jsonresponse.getstring("_id"));                 nametv.settext(jsonresponse.getstring("name"));                 firstnametv.settext(jsonresponse.getstring("firstname"));                 emailtv.settext(jsonresponse.getstring("email"));                 sextv.settext(jsonresponse.getstring("sex"));                 yeartv.settext(jsonresponse.getstring("year"));                 cursustv.settext(jsonresponse.getstring("cursus"));             } catch (jsonexception e) {                 onloadprofilefail();             }         }     };     profilerequest profilerequest = new profilerequest(user_id, responselistener);     requestqueue queue = volley.newrequestqueue(profileactivity.this);     queue.add(profilerequest); } 

request class

class profilerequest extends stringrequest {     private static final string user_profile_request = "http://[ipaddress]:8080/users/:id";     private map<string, string> params;      public profilerequest(string id, response.listener<string> listener) {         super(method.post, user_profile_request, listener, null);         params = new hashmap<>();         params.put("id", id);     }      @override     public map<string, string> getparams() {         return params;     } } 

app.js

router.get('/users/:id', function(req, res) {     user.find({ _id: "ie00847" }, function(err, user) {       if (err)           res.send(err);       res.json(user);     }); }); 

you got 404 error since you're accessing route method (post) not available, because in app.js file defined function request rather post request need update android code request. following,

class profilerequest extends stringrequest {     private static final string user_profile_request = "http://[ipaddress]:8080/users";     private map<string, string> params;      public profilerequest(string id, response.listener<string> listener) {         super(method.get, user_profile_request + "/" + id, listener, null);     } } 

also note there no need overriding getparams() method you're not sending post request anymore. in addition, can't add parameters request except through hard-coding values in url , not through map object.

hope helps :)


Comments

Popular posts from this blog

inversion of control - Autofac named registration constructor injection -

verilog - Systemverilog dynamic casting issues -

ios - Change Storyboard View using Seague -