简体   繁体   English

在Sony z2上从图库中选取图像时发生IllegalArgumentException

[英]IllegalArgumentException while picking image from gallery on Sony z2

When I run script on Sony Z2 it throws this Exception, although it runs smoothly in Samsung s4: 当我在Sony Z2上运行脚本时,它会抛出此异常,尽管它在Samsung s4中运行平稳:

Caused by: java.lang.IllegalArgumentException: filename cannot be null 原因:java.lang.IllegalArgumentException:文件名不能为null

at (MyDetailsPage.java:274) 在(MyDetailsPage.java:274)

And here is my program and java:274 is in outside code: 这是我的程序,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;
    }

Ok, It seems ridiculous, just writing answer and hope will help someone. 好吧,这似乎很荒谬,只写答案就可以对别人有所帮助。 It is really wierd how it affects whole code. 它如何影响整个代码真的很奇怪。 When calling intent I used 当我调用意图时

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

Instead of 代替

intent.setAction(Intent.ACTION_GET_CONTENT);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从图库中选择图片时获取NullPointerException - Getting NullPointerException while picking Picture From Gallery 从库中选取图像时发生FileNotFoundException - FileNotFoundException while picking images from gallery 在Android应用程序中从图库中选取图像 - image picking from gallery in android application 从库中选取图像时出现FileNotFoundException - FileNotFoundException when picking image from Gallery 从android图像库中选择并将其加载到另一个活动中不起作用 - picking from android image gallery and loading it into another activity not working 从图库中选取图片会导致Android N错误 - Picking an image from gallery gives error Android N 从图库中选取图像后,android应用程序崩溃-cursor.getColumnIndex返回-1 - android app crashes after picking a image from gallery - cursor.getColumnIndex returns -1 在Java中读取图像时出现IllegalArgumentException - IllegalArgumentException while reading an image in java 从图库获取图像时如何获取图像名称? - How to get Image name while getting image from gallery? 如何使用Quartz库每天在XX:XX处安排从日期X1 / Y1 / Z1到日期X2 / Y2 / Z2的某些任务? - How can I use Quartz library to schedule some task from date X1/Y1/Z1 to date X2/Y2/Z2 at XX:XX every day?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM