+ Start a Discussion
Taresh PandeyTaresh Pandey 

Compile time error

Hello all,
          This code having error while compiling I.e. Incompatible element type Another.Runtime for collection of Integer at line 20 column 17. Friends I'm not able to understand this error, please let me know if you can figureout this error.

Public class Another
{
    public class Runtime
    {
        Public string name;
        Public boolean Exist;
        public Integer Phone;
    }
    public List<Runtime> RuntimeList (List<Runtime> LR)
    {
        return LR;
    }
    public List<Integer> Phonenumbers (List<Integer> Phnumber)
    {
        List<integer> Allrecords = new List<integer> ();
        for(Runtime IT : Phnumber)
        {
            If(IT!=null)
            {
                Allrecords.add(IT);
            }
        }
    }
}

 
Best Answer chosen by Taresh Pandey
Abhishek BansalAbhishek Bansal
Hi Taresh,

Please change our code as mentioned below :
 
Public class Another
{
    public class Runtime
    {
        Public string name;
        Public boolean Exist;
        public Integer Phone;
    }
    public List<Runtime> RuntimeList (List<Runtime> LR)
    {
        return LR;
    }
    public List<Integer> Phonenumbers (List<Integer> Phnumber)
    {
        List<integer> Allrecords = new List<integer> ();
        for(Integer IT : Phnumber)
        {
            If(IT!=null)
            {
                Allrecords.add(IT);
            }
        }
    }
}

Phnumber is list of Integer and you are using Runtime that's why error is coming.
Hope that helps you.

Regards,
Abhishek.
 

All Answers

Abhishek BansalAbhishek Bansal
Hi Taresh,

Please change our code as mentioned below :
 
Public class Another
{
    public class Runtime
    {
        Public string name;
        Public boolean Exist;
        public Integer Phone;
    }
    public List<Runtime> RuntimeList (List<Runtime> LR)
    {
        return LR;
    }
    public List<Integer> Phonenumbers (List<Integer> Phnumber)
    {
        List<integer> Allrecords = new List<integer> ();
        for(Integer IT : Phnumber)
        {
            If(IT!=null)
            {
                Allrecords.add(IT);
            }
        }
    }
}

Phnumber is list of Integer and you are using Runtime that's why error is coming.
Hope that helps you.

Regards,
Abhishek.
 
This was selected as the best answer
Taresh PandeyTaresh Pandey
thank you Abhishek ... that issue has been resolved.