我们可以在try块中创建按钮功能

时间:2014-10-01 20:15:44

标签: java try-catch

我试图在try块中创建按钮功能,但它显示我的错误,下面是我的代码,我正在尝试使用onAvtivityResult内的按钮功能

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode != Activity.RESULT_OK) {return;}

        if (requestCode == REQUEST_IMAGE) {
            Uri uri = data.getData();
        try
          {
            InputStream is = this.getContentResolver().openInputStream(uri);
            final Bitmap bmInImg = BitmapFactory.decodeStream(is);
            bmInImg.getPixels(mPhotoIntArray, 0, bmInImg.getWidth(), 0, 0, bmInImg.getWidth(), bmInImg.getHeight());
            bmInImg2.getPixels(vPhotoIntArray, 0, bmInImg2.getWidth(), 0, 0, bmInImg2.getWidth(), bmInImg2.getHeight());
            mCannyOutArray = new int[bmInImg2.getWidth() * bmInImg2.getHeight()];
            final Bitmap bmOutImg = Bitmap.createBitmap(bmInImg2.getWidth(), bmInImg2.getHeight(), Config.ARGB_8888);  
            bmOutImg.setPixels(mCannyOutArray, 0, bmInImg2.getWidth(), 0, 0, bmInImg2.getWidth(), bmInImg2.getHeight());

            Button button= (Button) findViewById(R.id.NextButton);
            button.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v)  {  
                    negative(bmInImg.getHeight(),bmInImg.getWidth(), mPhotoIntArray, mCannyOutArray);
                    bmOutImg.setPixels(mCannyOutArray, 0, bmInImg.getWidth(), 0, 0, bmInImg.getWidth(), bmInImg.getHeight());   
                    imageview_2.setImageBitmap(bmOutImg);
                    }
                }

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

当鼠标停留在按钮功能的}上时显示错误:

button.setOnClickListener(new OnClickListener() {

@Override

1 个答案:

答案 0 :(得分:0)

您没有正确关闭anonymous inner class

button.setOnClickListener(new OnClickListener() {
  @Override
  public void onClick(View v)  {  
    negative(bmInImg.getHeight(),bmInImg.getWidth(), mPhotoIntArray, mCannyOutArray);
    bmOutImg.setPixels(mCannyOutArray, 0, bmInImg.getWidth(), 0, 0, 
        bmInImg.getWidth(), bmInImg.getHeight());   
    imageview_2.setImageBitmap(bmOutImg);
  }
}); // <-- close the OnClickListener