Volley Post JsonArrayRequest不传递带参数的UserID

时间:2016-05-16 10:45:58

标签: android parsing

我想解析一个将userID作为参数之一的Web服务,但它传递给errorResponse,在我的用户ID上设置nullpointerexception:

Url解析:

    Fav.setOnClickListener(new View.OnClickListener() {
    @Override
   public void onClick(View v) {
    Log.d("Favorite", "back");


    String tag_string_req = "favori";

    StringRequest strReq = new StringRequest(Request.Method.POST,
            AppConfig.URL_VOL_FAV, new Response.Listener<String>() {
        @Override
        public void onResponse(String response) {
            Log.d(TAG, " Favorite Response: " + response);
            //  hideDialog();
            try {

                JSONObject jObj = new JSONObject(response);
                String status = jObj.getString("success");
                Log.d("success: ", status);
                if (status.equals("successSaving")||
                (status.equals("no_such_user_id"))) {
                    JSONObject jsonResponse = new JSONObject(response);
                    Toast.makeText(getApplicationContext(), "Added to   
                   favoris! ", Toast.LENGTH_LONG).show();
                    Log.d("Fresponse: ", response);

                         flight=jsonResponse.getJSONArray("0").getString(Integer.parseInt("id"));
                      flight =jsonResponse.getString("numero_vol");
                      flight =jsonResponse.getString("destination_vol");
                      flight =jsonResponse.getString("depart_vol");
                      flight =jsonResponse.getString("date_depart");
                      flight =jsonResponse.getString("date_arrivee");
                      flight =jsonResponse.getString("temps_depart");
                      flight =jsonResponse.getString("temps_arrivee");
                      flight =jsonResponse.getString("nom_compagnie");
                      flight =jsonResponse.getString("id_airport");
                      flight =jsonResponse.getString("id_compagnie");
                      flight =jsonResponse.getString("id_mobile_user");
                      flight =jsonResponse.getString("commentaire");
                      flight =jsonResponse.getString("type_vol");


                }
                else {
                    Toast.makeText(getApplicationContext(), "Could not save 
                flight, try again! ", Toast.LENGTH_LONG).show();
                }

            } catch (JSONException e) {
                e.printStackTrace();
            }


        }
    }, new Response.ErrorListener() {

        @Override
        public void onErrorResponse(VolleyError error) {
            Log.e(TAG, "Favorite Error: " + error.getMessage());
            Toast.makeText(getApplicationContext(),
                    error.getMessage(), Toast.LENGTH_LONG).show();
            //    hideDialog();
            Toast.makeText(getApplicationContext(), "Error accured2",   
             Toast.LENGTH_LONG).show();
        }
        }) {

        @Override
        protected Map<String, String> getParams() {
            // Posting params to register url

            Map<String, String> params = new HashMap<String, String>();
            params.put("numero_vol", Numv);
            params.put("destination_vol", Des);
            params.put("depart_vol", Air);
            params.put("date_depart", Date);
            params.put("date_arrivee", Date);
            params.put("temps_depart", heur);
            params.put("temps_arrivee","");
            params.put("nom_compagnie", Compagnie);
            params.put("id_mobile_user", "");
            params.put("id_compagnie", user.getUser_ID());
            params.put("type_vol","A");
            params.put("commentaire",Com);


            return params;
        }

    };

    // Adding request to request queue
    AppController.getInstance().addToRequestQueue(strReq, tag_string_req);
}


 });

这是我的用户模型:

   @Table(name = "User")
   public class User extends Model {
   @Column(name = "User_ID")
   public String User_ID;

   @Column(name = "first_name")
   public String first_name;
  @Column(name = "last_name")
  public String last_name;
   @Column(name = "email")
  public String email;
  @Column(name = "password")
  public String password;
  @Column(name = "sexe")
  public String sexe;
  @Column(name = "Tel")
 public String Tel;
 @Column(name = "Nationality")
 public String Nationality;
  @Column(name = "eStatus")
 public String eStatus;// Active, Inactive,Pending,Deleted


 public User (){
   super();
   } 


public User (String User_ID,String first_name ,String last_name,String   
email,String password,String sexe,String Tel, String Nationality , String 
eStatus )
{
this.User_ID=User_ID;
this.first_name=first_name;
this.last_name=last_name;
this.email=email;
this.password=password;
this.sexe=sexe;
this.Tel=Tel;
this.Nationality=Nationality;
this.eStatus=eStatus;
}

public static User getUser(String id) {
    return new Select()
            .from(User.class)
            .where("User_ID = ?", id)
            .executeSingle();
}


public void setUser_ID(String User_ID) {this.User_ID = User_ID;}

public void setFirst_name(String first_name) {this.first_name = first_name;}

public void setLast_name(String last_name) {this.last_name = last_name;}

public void setEmail(String email) {
    this.email = email;
}

public void setPassword(String password) {
    this.password = password;
}

public void setSexe(String sexe) {
    this.sexe = sexe;
}

public void setTel(String Tel) {this.Tel= Tel;}
public void setNationality(String Nationality) {this.Nationality = Nationality;}


public String getUser_ID() {return User_ID;}

public String getFirst_name() {return first_name;}

public String getLast_name() {
    return last_name;
}

public String getEmail() {
    return email;
}

public String getPassword() {
    return password;
}

public String getSexe() {
    return sexe;
}
public String getTel() {return Tel;}
public String getNationality() {return  Nationality;}

我在这里想念的是什么?

0 个答案:

没有答案