Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 2002
    Posts
    22

    Question Unanswered: Converting an array length to a string

    Hello,

    if I want to compile the following script with javac then there comes this error message:





    class TestFromInt_3{

    static Integer _iD;


    static String FromInt(Integer val){
    return"";
    }


    public static void main (String arguments[]) {

    String _sD = "";
    _sD = FromInt(_iD);



    String _sT = "";
    String[] _asT = {"a","b"};
    _sT = FromInt(100/_asT.length);


    }
    }




    TestFromInt_3.java:41: FromInt(java.lang.Integer) in TestFromInt_2 cannot be app
    lied to (int)
    _sT = FromInt(100/_asT.length);
    ^
    1 error


    As you can see the problem is not in the function FromInt. The line
    _sD = FromInt(_iD);
    can be compiled without error message. The problem is 100/_asT.length.

    How can I solve this problem?

    Thank you,
    Flo

  2. #2
    Join Date
    Jun 2003
    Location
    Toronto, Canada
    Posts
    5,516
    Provided Answers: 1

    Re: Converting an array length to a string

    Originally posted by Rasti

    TestFromInt_3.java:41: FromInt(java.lang.Integer) in TestFromInt_2 cannot be app
    lied to (int)
    _sT = FromInt(100/_asT.length);
    ^
    1 error


    It may surprise you but "java.lang.Integer" and "int" are different things. As the error message says, your FromInt() method expects a java.lang.Integer parameter but you're trying to pass an int. Convert int to an Integer before calling the method, e.g.

    _sT = FromInt(new Integer(100/_asT.length));
    ---
    "It does not work" is not a valid problem statement.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •