Android - 无法解析方法'onActivityResult(int,int,android.content.Intent)

Posted

技术标签:

【中文标题】Android - 无法解析方法\'onActivityResult(int,int,android.content.Intent)【英文标题】:Android - Cannot resolve method 'onActivityResult(int, int, android.content.Intent)Android - 无法解析方法'onActivityResult(int,int,android.content.Intent) 【发布时间】:2016-05-08 13:10:20 【问题描述】:

我需要设置/添加照片/电影作为 ToDo 应用的附件。 不幸的是: onActivityResult 行 super.onActivityResult(requestCode, resultCode, data);以红色突出显示,我收到错误消息:

“无法解析方法'onActivityResult(int, int, android.content.Intent)'”

AddActivity.java

    Button button_z = (Button) findViewById(R.id.button_z);
        button_z.setonclickListener(new View.onclickListener() 
                @Override
                public void onclick(View view2) 

                    selectImage();
 
           @Override 
    protected void onActivityResult(int requestCode, int resultCode, Intent  data) 
                    super.onActivityResult(requestCode, resultCode, data);
                    if (resultCode == RESULT_OK) 
                        if (requestCode == REQUEST_CAMERA) 

                  Bitmap thumbnail = (Bitmap) data.getExtras().get("data");
                           90, bytes);
                            ByteArrayOutputStream bytes = new ByteArrayOutputStream();
                            thumbnail.compress(Bitmap.CompressFormat.JPEG, 90, bytes);
                            File destination = new File(Environment.getExternalStorageDirectory(),
                                    System.currentTimeMillis() + ".jpg");
                            FileOutputStream fo;
                            try 
                                destination.createNewFile();
                                fo = new FileOutputStream(destination);
                                fo.write(bytes.toByteArray());
                                fo.close();
                             catch (FileNotFoundException e) 
                                e.printStackTrace();
                             catch (IOException e) 
                                e.printStackTrace();
                            
                            imageView.setImageBitmap(thumbnail);
                         else if (requestCode == SELECT_FILE) 

                            Uri selectedImageUri = data.getData();
                            String[] projection = MediaStore.MediaColumns.DATA;
                            CursorLoader cursorLoader = new CursorLoader(AddActivity.this, selectedImageUri, projection, null, null, null);
                            Cursor cursor = cursorLoader.loadInBackground();
                            int column_index = cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.DATA);
                            cursor.moveToFirst();
                            String selectedImagePath = cursor.getString(column_index);
                            Bitmap bm;
                            BitmapFactory.Options options = new BitmapFactory.Options();
                            options.inJustDecodeBounds = true;
                            BitmapFactory.decodeFile(selectedImagePath, options);
                            final int REQUIRED_SIZE = 200;
                            int scale = 1;

                            while (options.outWidth / scale / 2 >= REQUIRED_SIZE
                                    && options.outHeight / scale / 2 >= REQUIRED_SIZE)
                                scale *= 2;
                            options.inSampleSize = scale;
                            options.inJustDecodeBounds = false;
                            bm = BitmapFactory.decodeFile(selectedImagePath, options);
                            imageView.setImageBitmap(bm);
                        
                    

        private void selectImage() 
            final CharSequence[] items =  "Zrób zdjęcie lub nagranie", "Wybierz istniejące", "Anuluj" ;

            AlertDialog.Builder builder = new AlertDialog.Builder(AddActivity.this);
            builder.setTitle("Dodaj załącznik");
            builder.setItems(items, new DialogInterface.onclickListener() 
                @Override
                public void onclick(DialogInterface dialog, int item) 
                    if (items[item].equals("Zrób zdjęcie lub nagranie")) 
                        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                        startActivityForResult(intent, REQUEST_CAMERA);
                     else if (items[item].equals("Wybierz istniejące")) 
                        Intent intent = new Intent(
                                Intent.ACTION_PICK,
                                android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
                        intent.setType("image/*");
                        startActivityForResult(
                                Intent.createChooser(intent, "Wybierz plik"),
                                SELECT_FILE);
                     else if (items[item].equals("Anuluj")) 
                        dialog.dismiss();
                    
                
            );
            builder.show();
        
                

【问题讨论】:

【参考方案1】:

您的代码中缺少);

Button button_z = (Button) findViewById(R.id.button_z);
button_z.setonclickListener(new View.onclickListener() 
    @Override
    public void onclick(View view2) 

        selectImage();
    
);  //here

【讨论】:

以上是关于Android - 无法解析方法'onActivityResult(int,int,android.content.Intent)的主要内容,如果未能解决你的问题,请参考以下文章

Android Location Client 无法解析方法

无法解析 Android 中的方法“execute()”

无法解析 Android 应用程序中的掷骰子游戏方法

无法通过 `api` 方法从 Android 模块解析主题和样式

我正在尝试在 android 中解析 Preferences Xml 文件,但无法解析 getAttribute Count 方法始终返回零

Android Studio 错误“无法解析方法 .add 的方法”