打开图像时如何解决此错误

时间:2019-10-25 10:52:36

标签: android nullpointerexception

这是 OpenImage代码

private void openWebView(String docPath) {

            if (docPath.toLowerCase().endsWith("png") ||
                    docPath.toLowerCase().endsWith("jpg") ||
                    docPath.toLowerCase().endsWith("jpeg")) {

                urlWebView.setVisibility(View.GONE);
                imgBelow.setVisibility(View.GONE);
    //            Glide.with(CalanderAssignmentDetailActivity.this).load(docPath)
    //                    .diskCacheStrategy(DiskCacheStrategy.SOURCE)
    //                    .error(R.mipmap.ic_launcher)
    //                    .crossFade()
    //                    .into(imgBelow);
                images = new ArrayList<>();
                images.add(new CustomImage(docPath, "1"));

                overlayView = new ImageOverlayView(CalanderAssignmentDetailActivity.this);
                imagrBuliderDilog = new ImageViewer.Builder<>(CalanderAssignmentDetailActivity.this, images)
                        .setFormatter(getCustomFormatter())
                        .setStartPosition(0)
                        .setImageChangeListener(getImageChangeListener())
                        .setOverlayView(overlayView)
                        .show();
                overlayView.setImageDilogListner(imagrBuliderDilog);

            } else {
                imgBelow.setVisibility(View.GONE);
                urlWebView.setVisibility(View.VISIBLE);
                urlWebView.loadUrl("http://docs.google.com/gview?embedded=true&url="
                        + docPath);

            }
        }

这是 LOGCAT错误

  

W / System.err:java.lang.NullPointerException:尝试在空对象引用上调用虚拟方法'java.lang.String java.lang.String.toLowerCase()'

1 个答案:

答案 0 :(得分:0)

您确定docPath不为空或为空吗?

尝试一下:

if(docPath !=null && !docPath.isEmpty()){
   //your code
}