1. Are you ready for the Galaxy S20? Here is everything we know so far!

What's the difference between "Array<Uri>?" and "Array<Uri?>"?

Discussion in 'Android Development' started by Daniel Fernandes, Jan 16, 2020.

  1. Daniel Fernandes

    Daniel Fernandes Android Enthusiast
    Thread Starter

    I get this type mismatch error that I don't really understand, I've been stuck on it for quite a long while and I haven't really figured it out. The error looks like this:

    Type inference failed. Expected type mismatch:
    required: Array<Uri>?
    found: Array<Uri?>

    What exactly does the question mark mean and what's the difference in their positions?

    I get this error at onActivityResult. The activity has a webview. When the user clicks an "Upload Image" button on the website, the app shows a file chooser, and gets the result back, then the image is sent to webview. Here's its code snippet:

    Code (Text):
    1. override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
    2.         super.onActivityResult(requestCode, resultCode, data)
    3.         if(resultCode == file_req_code){
    4.             if (resultCode == Activity.RESULT_CANCELED) {
    5.                 file_path?.onReceiveValue(null) //file_path is the filePathCallback
    6.                 return
    7.             }
    9.             if(resultCode == Activity.RESULT_OK){
    10.                 if (file_path == null){
    11.                     return
    12.                 }
    13.                 var image: Array<Uri>? = null
    14.                 image = arrayOf(data.data) //I get the error here! "arrayOf(data.data)" is underlined in red.
    15.                 file_path?.onReceiveValue(image)
    16.             }
    17.         }
    18.     }

    racibennett likes this.

    1. Download the Forums for Android™ app!



Share This Page