I have a code which I tried to compile for the first time, and when I was about to compile it sent me two errors:
Error: java.lang.RuntimeException: Some file crunching failed, see logs for details
Error: Execution failed for task ': app: mergeDebugResources'.
Error: java.lang.RuntimeException: Some file crunching failed, see logs for details
This is my code:
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
ImageView img;
Button immg;
private final int PICKER = 1;
String encodedImage,foto,funcion;
DataConnctcion dc;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});
img = (ImageView)findViewById(R.id.imageView2);
immg = (Button) findViewById(R.id.button);
immg.setOnClickListener(this);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_send) {
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
public void onClick(View v) {
PickFile();
}
private void PickFile(){
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("image/*");
try {
startActivityForResult(
Intent.createChooser(intent, "Instale un administrador de archivos."), PICKER);
}catch (android.content.ActivityNotFoundException ex){
}
}
protected void onActivityResult(int requestCode, int sesultCode, Intent data){
switch (requestCode){
case PICKER:
if (requestCode == RESULT_OK){
foto = "foto";
Bitmap photobmp;
Uri selectdImageUri = data.getData();
String dataFU = getRealPathFromURI(selectdImageUri);
photobmp = BitmapFactory.decodeFile(dataFU);
img.setImageBitmap(photobmp);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
photobmp.compress(Bitmap.CompressFormat.JPEG,88,baos);
byte[] imageBytes = baos.toByteArray();
encodedImage = Base64.encodeToString(imageBytes, Base64.DEFAULT);
}
break;
}
}
public String getRealPathFromURI(Uri contentUri){
Cursor cursor = null;
try {
String[] proj = {MediaStore.Images.Media.DATA};
cursor = getApplicationContext().getContentResolver().query(contentUri, proj, null, null, null);
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);
}finally {
if (cursor != null){
cursor.close();
}
}
}
}
Can you tell me why these errors occur and how can I solve them?