'TypeError: Data location must be "memory" for parameter in function, but none was given

I tried to compile my code, but I got the following error:

TypeError: Data location must be "memory" for parameter in function, but none was given

my code:

pragma solidity ^0.5.0;

contract memeRegistry {
    string url;
    string name;
    uint timestamp;

    function setmeme(string _url,string _name, uint _timestamp) public{
        url = _url;
        name = _name;
        timestamp = _timestamp;   
    }
}


Solution 1:[1]

Explicit data location for all variables of struct, array or mapping types is now mandatory. This is also applied to function parameters and return variables.

Add memory after string

function setmeme(string memory _url, string memory _name, uint _timestamp) public{

check here for Solidity 0.5.0. changes https://solidity.readthedocs.io/en/v0.5.0/050-breaking-changes.html

Solution 2:[2]

//The version I have used is 0.5.2

pragma solidity ^0.5.2;

contract Inbox{


string public message;

//**Constructor** must be defined using “constructor” keyword

//**In version 0.5.0 or above** it is **mandatory to use “memory” keyword** so as to 
//**explicitly mention the data location**

//you are free to remove the keyword and try for yourself

 constructor (string memory initialMessage) public{
 message=initialMessage;
 }

 function setMessage(string memory newMessage)public{
 message=newMessage;

 }

 function getMessage()public view returns(string memory){
 return message;
 }
}

Solution 3:[3]

Select a different version of the solidity compiler. ^0.4.25 works for me.

The version of the solidity compiler has to be set both on the file and in the compile tab on remix(it is a drop-down menu).

Solution 4:[4]

It's working for me.

  • string memory firstname

enter image description here

Solution 5:[5]

You need to make the return parameters explicitly memory:

Thus,

function setmeme(string _url,string _name, uint _timestamp) public

Becomes

function setmeme(string memory _url, string memory _name, uint _timestamp) public{

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Marcelo Fonseca
Solution 2 Kartik ganiga
Solution 3
Solution 4 Abdullah
Solution 5 Chris Catignani