Android Volley kütüphanesini kullanarak görüntü ve metin gönderebiliyorum. Ancak Volley kütüphanesini kullanarak görüntülerin isteğe bağlı olarak nasıl kaydedilebileceğini? Sadece metin göndermeyi denediğimde Java null pointer exception
atıldı. Opsiyonel içinde olmak için kodundan `veya boş olup olmadığını kontrol edebilirsiniz; Sorunuzu doğru anlamakAndroid Volley kullanarak görüntü veya metin gönderme veya her ikisi de gönderme
private void uploadImage(){
//Showing the progress dialog
final ProgressDialog loading = ProgressDialog.show(this,"Uploading...","Please wait...",false,false);
StringRequest stringRequest = new StringRequest(Request.Method.POST, UPLOAD_URL, new Response.Listener<String>() {
@Override
public void onResponse(String s) {
//Disimissing the progress dialog
loading.dismiss();
//Showing toast message of the response
Toast.makeText(PostActivity.this, s, Toast.LENGTH_LONG).show();
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError volleyError) {
//Dismissing the progress dialog
loading.dismiss();
//Showing toast
Toast.makeText(PostActivity.this, volleyError.getMessage(), Toast.LENGTH_LONG).show();
}
}) {
@Override
protected Map<String, String> getParams() throws AuthFailureError {
//Converting Bitmap to String
String rimage = null;
try {
rimage = getStringImage(bitmap);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
//Getting Image Name
String FName = FoodName.getText().toString().trim();
String LName = user.username;
//Creating parameters
Map<String, String> params = new Hashtable<String, String>();
//Adding parameters
params.put(KEY_IMAGE, rimage);
params.put(KEY_NAME, FName);
params.put(KEY_LOGIN,LName);
//returning parameters
return params;
}
};
//Creating a Request Queue
RequestQueue requestQueue = Volley.newRequestQueue(this);
//Adding request to the queue
requestQueue.add(stringRequest);
}
, o zaman' params.put (KEY_IMAGE, Rimage) kaldırmak gerekir value if if (someImage! = null) {params.put (KEY_IMAGE, rimage); } ' –