Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/179.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 试图获取联系人照片时发生IllegalArgumentException_Android - Fatal编程技术网

Android 试图获取联系人照片时发生IllegalArgumentException

Android 试图获取联系人照片时发生IllegalArgumentException,android,Android,我正在开发一个联系人应用程序,它可以显示未接来电、已拨电话,当手机号码不是的人打电话时会出现问题,我有一个方法,尝试根据手机号码获取来电者姓名,然后另一个方法根据号码获取联系人ID,然后是姓名,号码和contactID保存在SQLlited数据库中如果来电者未保存在电话簿中contactID被分配一个随机整数,当我想检索来电者时,我调用一个方法获取号码、姓名和contactID,在显示时我使用contactID在电话中运行并检索来电者的显示图片,但从联系人未保存、检索呼叫方的方法未保存、cont

我正在开发一个联系人应用程序,它可以显示未接来电、已拨电话,当手机号码不是的人打电话时会出现问题,我有一个方法,尝试根据手机号码获取来电者姓名,然后另一个方法根据号码获取联系人ID,然后是姓名,号码和contactID保存在SQLlited数据库中如果来电者未保存在电话簿中contactID被分配一个随机整数,当我想检索来电者时,我调用一个方法获取号码、姓名和contactID,在显示时我使用contactID在电话中运行并检索来电者的显示图片,但从联系人未保存、检索呼叫方的方法未保存、contactID变量中存储的随机值与手机匹配的情况来看,如果发生这种情况,我会在context.getContentResolver.queryphotoUri上获得IllegalArgumentException异常, 新字符串[]{ContactsContract.Contacts.Photo.Photo},null,null,null;这是我返回显示位图的完整方法

  public Bitmap openPhoto(long contactId, Context context) {
    Uri contactUri = ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, contactId);
    Uri photoUri = Uri.withAppendedPath(contactUri, ContactsContract.Contacts.Photo.CONTENT_DIRECTORY);
    Cursor cursor = context.getContentResolver().query(photoUri,
            new String[]{ContactsContract.Contacts.Photo.PHOTO}, null, null, null);
    if (cursor == null) {
        return null;
    }
    try {
        if (cursor.moveToFirst()) {
            byte[] data = cursor.getBlob(0);
            if (data != null) {

                Log.d("BTmap","Bitmap Exists");
                return BitmapFactory.decodeStream(new ByteArrayInputStream(data));
            }
        }
    } finally {
        cursor.close();
    }
    Log.d("BTmap","Bitmap Dont Exist");
    return null;


}

有谁能帮我克服这个错误吗?当我在IllegalArgumentException中运行openPhoto方法时,try catch block Non的显示图片即使是保存在通讯录中并带有图像的图片也会加载,提前谢谢。

我解决了这个问题,这很简单,首先,我必须检查呼叫的号码是否保存在我的电话簿中,如果没有,我将名称设置为未保存,然后在适配器中,我必须检查adapter.getName值是否等于未保存,如果是,则无需加载图像,我只需将imageview指定为null或默认显示图片