#获取系统图片遇到的坑--Cursor空指针异常

获取系统图片遇到的坑–Cursor空指针异常

Cursor 空指针异常:
小米N2测试的时候报Cursor空指针异常的错误

   Uri photoUri = data.getData();
   Uri photoUri = data.getData();

            if (null == photoUri) {
                return;
            }
            //获取照片路径
            String[] filePathColumn = {MediaStore.Audio.Media.DATA};
            Cursor cursor = getContentResolver().query(photoUri, filePathColumn, null, null, null);
            cursor.moveToFirst();
            mPhotoPath = cursor.getString(cursor.getColumnIndex(filePathColumn[0]));
            cursor.close();
 getContentResolver().query(photoUri, filePathColumn, null, null, null);

返回未空,修改如下,做判断

 if (cursor != null) {
                cursor.moveToFirst();
                int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
                String picturePath = cursor.getString(columnIndex);
                cursor.close();
                mPhotoPath = picturePath;
            } else {
                mPhotoPath = photoUri.getPath();
            }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
可以根据需要进行如下优化和完善: 1. 在 `#homemasthead` 中添加 `height: 100vh;` 属性,将其高度设置为视口高度,使其占据整个屏幕空间。 2. 在 `#nav` 中添加 `padding: 10px 0;` 属性,将上下内边距设置为10像素,使其更加美观。 3. 在 `.display-1` 中添加 `font-weight: bold;` 属性,将字体加粗,使其更加醒目。 4. 在 `#footer` 中添加 `text-align: center;` 属性,将文本内容居中显示。 5. 在 `#links` 中添加 `cursor: pointer;` 属性,将鼠标样式设置为手型,增加交互性。 6. 在 `a:hover` 中添加 `text-decoration: none;` 和 `font-weight: bold;` 属性,将链接悬停时的下划线去掉,将字体加粗。 7. 在 `#references` 中添加 `cursor: pointer;` 属性,将鼠标样式设置为手型,增加交互性。 修改后的 CSS 代码如下: ```css @charset "utf-8"; /* CSS Document */ #homemasthead { background-image: url("Images/grass.jpg"); background-size: cover; background-position: center; font-family: 'Fuzzy Bubbles', cursive; height: 100vh; } #nav { background-color: #AFEBAA; font-family: 'BIZ UDPMincho', serif; padding: 10px 0; } .bg-dark { background-color: #476C9A !important; } .display-1 { font-size: 80px; font-weight: bold; } #home { background-color: #C7DDF8; font-family: 'BIZ UDPMincho', serif; } #about { background-color: #C7DDF8; font-family: 'BIZ UDPMincho', serif; } #footer { background-color: #476C9A; font-family: 'Fuzzy Bubbles', cursive; color: #F8FBBE; text-align: center; } #links { font-family: 'Fuzzy Bubbles', cursive; text-decoration: underline; cursor: pointer; } a { color: black; } a:link, a:visited { color: #F8FBBE; } a:hover { color: #B2BC1A; text-decoration: none; font-weight: bold; } #references { text-decoration: underline; cursor: pointer; } #refimages a { color: #00B510; text-decoration: underline; } ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值