0

I am getting error as

Constructor not defined: [weather001.weatherresult].()

at the time of creating instance for wrapper class. below is the code.

public class weather001 {

    public string city {set;get;}
    public string result {set;get;}
    public string nameofcity {set;get;}
    public list<weatherresult> wccc{set;get;}
    public weatherresult wc{set;get;}



    public void makeGetCallout() {

        Http http = new Http();

        HttpRequest request = new HttpRequest();
        String requestEndpoint = 'https://api.openweathermap.org/data/2.5/forecast';

       requestEndpoint += '?q=' + city;
        requestEndpoint += '&units=metric';
    requestEndpoint += '&APPID=' + '21ea14e29fcf2a9f90a209e267f7847c';

        request.setEndpoint(requestEndpoint );

        request.setMethod('GET');

        // The response is in JSON format.

        HttpResponse response = http.send(request);
        if (response.getStatusCode() == 200) {
            result =response.getBody();

            weatherresult wc = new weatherresult();


                    }
                }
    public class weatherresult{
        public Integer id {get;set;} 
        public String main {get;set;} 
        public String description {get;set;} 
        public String icon {get;set;} 
        public weatherresult(Integer k,string m,string des,string ic){
            id = k;
            main = m;
            description = des;
            icon = ic;
        }
    }
}

1 Answer 1

3

This error is pretty much exactly what it says. You're calling a no-argument constructor:

        weatherresult wc = new weatherresult(); 

but your wrapper class only defines one constructor, which requires four arguments:

    public weatherresult(Integer k,string m,string des,string ic)

You must either call the constructor with those four arguments, or define a no-argument constructor within the class weatherresult.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .