java - 在 Sony z2 上从图库中选取图像时出现 IllegalArgumentException

标签 java android illegalargumentexception

当我在 Sony Z2 上运行脚本时它抛出这个异常,尽管它在 Samsung s4 上运行顺利:

Caused by: java.lang.IllegalArgumentException: filename cannot be null

at (MyDetailsPage.java:274)

这是我的程序,java:274 在外部代码中:

 public  Bitmap decodeScaledDownBitmapFromDatabase(String imagePath,int requiredHeight,int requiredWidth){
       final BitmapFactory.Options options=new BitmapFactory.Options();
        options.inJustDecodeBounds=true;
        Bitmap bitmap=BitmapFactory.decodeFile(imagePath, options);
        Matrix matrix;

        options.inSampleSize=calculateInputImageSize(options, requiredHeight, requiredWidth);
        options.inJustDecodeBounds=false;
        bitmap =BitmapFactory.decodeFile(imagePath, options);
        int angel=0;


                    try{

java : 276         ExifInterface exifInterface=new ExifInterface(imagePath);

                   int orientation=exifInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION,ExifInterface.ORIENTATION_UNDEFINED);

                   if (orientation==ExifInterface.ORIENTATION_ROTATE_90){
                   angel=90;
                   }
                   else if(orientation==ExifInterface.ORIENTATION_ROTATE_180){
                angel=180;
            }
            else if (orientation==ExifInterface.ORIENTATION_ROTATE_270){
                angel=270;
            }
        }
        catch (IOException e){
            Toast.makeText(getApplicationContext(),"Image could not be selected",Toast.LENGTH_LONG).show();
        }
        matrix=new Matrix();
        matrix.postRotate(angel);
        Bitmap readyBitmap=Bitmap.createBitmap(bitmap,0,0,bitmap.getWidth(),bitmap.getHeight(),matrix,true);

        return readyBitmap;
    }

最佳答案

好吧,这看起来很荒谬,只是写下答案,希望能帮助到别人。它如何影响整个代码真的很奇怪。 调用 intent 时我使用了

Intent intent = new Intent();
intent.setAction(Intent.ACTION_PICK);

代替

intent.setAction(Intent.ACTION_GET_CONTENT);

关于java - 在 Sony z2 上从图库中选取图像时出现 IllegalArgumentException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34363365/

相关文章:

java - Hibernate 更新子集合

javascript - 过滤器未显示在网格中

java - Android 中的唤醒锁无法打开屏幕

java - Apache Commons 解压 : IllegalArgumentException with getNextTarEntry

android - 在异步任务中关闭对话框时出现 IllegalArgumentException

java - OrientDB图形API : process results of SQL query

java - 确定字符串中的每个字符是否包含全角字符

java - 如何在 Activity 之间共享点击处理程序

Android tabhost改变文字颜色样式

struts2 - 由 : java. lang.IllegalArgumentException 引起:未知的保留 key '_typeConverter'