图像上的Android黑屏点击(得到异常解码位图)

时间:2015-05-22 21:19:49

标签: android bitmap

我通过json / url将活动图像放到ListView中。然后我将图像与一些TextViews一起传递给details_activity。现在我正尝试使用Android的默认图库图像查看器打开全屏图像。

在图像上单击黑屏已打开,我在logcat中获得以下内容:

05-22 20:50:09.817: E/UriImage(564): got exception decoding bitmap 
05-22 20:50:09.817: E/UriImage(564): java.lang.NullPointerException
05-22 20:50:09.817: E/UriImage(564):    at       com.android.camera.Util.makeInputStream(Util.java:336)
05-22 20:50:09.817: E/UriImage(564):    at com.android.camera.Util.makeBitmap(Util.java:307)
05-22 20:50:09.817: E/UriImage(564):    at com.android.camera.Util.makeBitmap(Util.java:299)
05-22 20:50:09.817: E/UriImage(564):    at com.android.camera.gallery.UriImage.fullSizeBitmap(UriImage.java:94)
05-22 20:50:09.817: E/UriImage(564):    at com.android.camera.gallery.UriImage.fullSizeBitmap(UriImage.java:86)
05-22 20:50:09.817: E/UriImage(564):    at com.android.camera.gallery.UriImage.thumbBitmap(UriImage.java:120)
05-22 20:50:09.817: E/UriImage(564):    at com.android.camera.ImageGetter$ImageGetterRunnable.executeRequest(ImageGetter.java:173)
05-22 20:50:09.817: E/UriImage(564):    at com.android.camera.ImageGetter$ImageGetterRunnable.run(ImageGetter.java:149)
05-22 20:50:09.817: E/UriImage(564):    at java.lang.Thread.run(Thread.java:856)
05-22 20:50:09.876: E/UriImage(564): got exception decoding bitmap 
05-22 20:50:09.876: E/UriImage(564): java.lang.NullPointerException
05-22 20:50:09.876: E/UriImage(564):    at com.android.camera.Util.makeInputStream(Util.java:336)
05-22 20:50:09.876: E/UriImage(564):    at com.android.camera.Util.makeBitmap(Util.java:307)
05-22 20:50:09.876: E/UriImage(564):    at com.android.camera.Util.makeBitmap(Util.java:299)
05-22 20:50:09.876: E/UriImage(564):    at com.android.camera.gallery.UriImage.fullSizeBitmap(UriImage.java:94)
05-22 20:50:09.876: E/UriImage(564):    at com.android.camera.ImageGetter$ImageGetterRunnable.executeRequest(ImageGetter.java:204)
05-22 20:50:09.876: E/UriImage(564):    at com.android.camera.ImageGetter$ImageGetterRunnable.run(ImageGetter.java:149)
05-22 20:50:09.876: E/UriImage(564):    at java.lang.Thread.run(Thread.java:856)

details_activity.java

NetworkImageView file;
String image;
private static final String TAG_FILE = "imageFile";

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_details);

    file = (NetworkImageView) findViewById(R.id.file);

Intent i = getIntent();
image = i.getStringExtra(TAG_FILE);

ImageLoader imageLoader = AppController.getInstance().getImageLoader();
file.setImageUrl(image, imageLoader);

file.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent intent = new Intent();
            intent.setAction(Intent.ACTION_VIEW);
            intent.setDataAndType(Uri.parse("file://" + TAG_FILE), "image/*");
            startActivity(intent);

        }
    });
}

那么,我做错了什么?

1 个答案:

答案 0 :(得分:0)

您用于查看图片的外部活动无法访问该文件。您的URI也不是真正的calue,因为它不是root的完全限定文件路径。该文件需要位于一个文件夹中,该文件夹可以被随机活动访问(所以基本上是一个公共目录),并且需要有一个完整的URI(最简单的方法就是为它创建一个File对象,然后将其转换为一个URI)。

如果您不想将图片移动到公共目录,那么您必须做一些比ContentResolver更复杂的事情。