У меня ошибка в Android, кто-то может мне помочь?
мой код активности:
profileImage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
ActivityCompat.requestPermissions(
Connect.this,new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},CODE_GALLERY_REQUEST
);
}
});
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
if(requestCode==CODE_GALLERY_REQUEST){
if(grantResults.length>0 && grantResults[0]== PackageManager.PERMISSION_GRANTED){
Intent intent = new Intent(Intent.ACTION_PICK);
intent.setType("image/*");
startActivityForResult(Intent.createChooser(intent,"Select Image"),CODE_GALLERY_REQUEST);
}else {
Toast.makeText(this," Pour créer une photo de profil merci de nous donner la permission",Toast.LENGTH_SHORT);
}
return;
}
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if(requestCode==CODE_GALLERY_REQUEST&&resultCode==RESULT_OK&&data!=null){
Uri filePath=data.getData();
try {
InputStream inputStream = getContentResolver().openInputStream(filePath);
bitmap = BitmapFactory.decodeStream(inputStream);
imagedata = imageToString(bitmap);
profileImage.setImageBitmap(bitmap);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
super.onActivityResult(requestCode, resultCode, data);
}
private void updateLabel() {
String myFormat = "yyyy-MM-dd"; //In which you need put here
SimpleDateFormat sdf = new SimpleDateFormat(myFormat, Locale.FRANCE);
naissance.setText(sdf.format(myCalendar.getTime()));
}
public void inscription(View view){
final ProgressDialog progressDialog = new ProgressDialog(this);
progressDialog.setMessage("Chargement...");
progressDialog.show();
StringRequest stringRequest = new StringRequest(Request.Method.POST, URL_inscription,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
progressDialog.dismiss();
if(response.equals("SUCCES")){
// Intent intent = new Intent(getApplicationContext(),Connexion.class);
// startActivity(intent);
}else {
Toast.makeText(Connect.this, response, Toast.LENGTH_LONG).show();
}
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(getApplicationContext(),"verifier votre connexion internet et réessayer",Toast.LENGTH_LONG).show();
progressDialog.dismiss();
}
}){
@Override
protected Map<String, String> getParams() {
Map<String, String> params = new HashMap<String, String>();
params.put("image",imagedata);
params.put("pseudo",pseudo.getText().toString());
params.put("nom",nom.getText().toString());
params.put("prenom",prenom.getText().toString());
params.put("password",password.getText().toString());
params.put("email",email.getText().toString());
params.put("naissance",naissance.getText().toString());
return params;
}
};
RequestQueue requestQueue = Volley.newRequestQueue(this);
requestQueue.add(stringRequest);
}
private String imageToString(Bitmap bitmap){
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream);
byte[] byteArray = byteArrayOutputStream .toByteArray();
String encoded = android.util.Base64.encodeToString(byteArray, android.util.Base64.DEFAULT);
return encoded;
}
}
Стек ошибок:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: tn.events.events, PID: 16587
java.lang.OutOfMemoryError: Failed to allocate a 24551844 byte allocation with 8376560 free bytes and 14MB until OOM
at java.lang.StringFactory.newStringFromBytes(StringFactory.java:88)
at java.lang.StringFactory.newStringFromBytes(StringFactory.java:65)
at android.util.Base64.encodeToString(Base64.java:456)
at tn.events.events.Connect.imageToString(Connect.java:195)
at tn.events.events.Connect.onActivityResult(Connect.java:129)
at android.app.Activity.dispatchActivityResult(Activity.java:6674)
at android.app.ActivityThread.deliverResults(ActivityThread.java:4009)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:4056)
at android.app.ActivityThread.access$1400(ActivityThread.java:196)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1588)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:210)
at android.app.ActivityThread.main(ActivityThread.java:5982)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:852)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:742)