I am trying to create an ImageView that is resized when the user presses a MenuItem. I tried to use the following code, but I get an error and my application stops.
@Override
public boolean onOptionsItemSelected(MenuItem item)
{
switch(item.getItemId())
{
case R.id.sub_item_25_percent:
try
{
LayoutParams params = new LayoutParams(imageView1.getLayoutParams());
params.width = Pages.PAGE_WIDTH_25_PERCENT;
params.height = Pages.PAGE_HEIGHT_25_PERCENT;
imageView1.setLayoutParams(params);
}
catch(Exception ex)
{
Toast.makeText(this, ex.getMessage(), Toast.LENGTH_SHORT);
}
break;
}
}
As you can see, I already used a try-catch-block to get informations about the exception, but the application is still just stopping without displaying the Toast.
Does anyone have a clue what I could do to fix my problem?
Try this:
}