Results 1 to 5 of 5
  1. #1
    Nicholas Jordan's Avatar
    Nicholas Jordan is offline Senior Member
    Join Date
    Jun 2008
    Location
    Southwest
    Posts
    1,018
    Rep Power
    8

    Angry request.get not using generics

    Java Code:
    found   : java.util.Enumeration
    required: java.util.Enumeration<java.lang.String>
            java.util.Enumeration<String> paramNames = (java.util.Enumeration<String>) request.getParameterNames();
    This is from sample code at coreservlets that I am using. Getting the error and ignoring it is not advisable at this point, I assume the jar file that the IDE is using was not built using Generics. This is funny because it won't go ten minutes without asking me if I want to do the 'latest software'

    ( - 8 ? )

    Any suggestions on how to correct the code? I can use generics or not - I know every datatype in every line of code - but I need to have carefully preened builds right now.
    Introduction to Programming Using Java.
    Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,800
    Rep Power
    25

    Default

    I need just a bit more info to help. What is the full statement?
    What version of java?
    What type is request and what does getParameterNames return?
    What package is it in?
    Then I'll have to see if I have the current jar file for it.

  3. #3
    Nicholas Jordan's Avatar
    Nicholas Jordan is offline Senior Member
    Join Date
    Jun 2008
    Location
    Southwest
    Posts
    1,018
    Rep Power
    8

    Post

    Quote Originally Posted by Norm View Post
    I need just a bit more info to help. What is the full statement?
    ...NetBeansProjects\WebApplication1\src\java\##### \############.java
    line 485-507

    The code here is to capture some of the name=value pairs that were actually shipping from other parts of the program. Though coded as a temporary bench patch during prototyping to get something to work, the code here may become partially implemented in production code to provide trace logging in unanticipated uses.

    The code is almost verbatim from Marty Halls source code archive, by that I am saying that nothing beyond a few obvious keystrokes was considered in rewrite ~ I was trying to get unstuck.

    Java Code:
    while(paramNames.hasMoreElements())
    {
        String paramName = (String)paramNames.nextElement();
        ############.write("     " + paramName + this.LINE_ENDING);
        String[] paramValues = request.getParameterValues(paramName);
        if(paramValues != null)
        {
            if (paramValues.length == 1)
            {
                String paramValue = paramValues[0];
                if(paramValue!= null)
                {
                    if(paramValue.length() == 0)
                    {
                        ############.write("  No Value  ");
                    }
                    else
                    {
                        ############.write(paramValue);
                    }
                }
            }
            else
            {
                ############.write(TRANSACTION_SEPARATOR);
                for(int i=0; i<paramValues.length; i++)
                {
                    ############.write(paramValues[i]);
                }
                ############.write(TRANSACTION_SEPARATOR,0x0000,TRANSACTION_SEPARATOR.length());
            }
        }
    }
    Quote Originally Posted by Norm View Post
    What version of java?
    Java Version 6
    Quote Originally Posted by Norm View Post
    What type is request and what does getParameterNames return?
    Java Code:
        protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException
    Quote Originally Posted by Norm View Post
    What package is it in?
    It's part of a package that vastly simplifies a lot of network programming under http protocol. The package is used throughout Marty Hall's coreservlets books and web pages. I had downloaded and installed NetBeans recently on the advices of ftr, thus if it is not the latest dot jar file then we have issues beyond the scope of the immediate question.
    Quote Originally Posted by Norm View Post
    Then I'll have to see if I have the current jar file for it.
    In paticular I will have to find where it keeps it's jar files, I can get that from a link on the Java site if you wish to do the search. Good results can come from that, probably just a matter of doing the research. You are welcome to make this a parallel search for improved reliablitly. We can compare resultant opinions.
    Introduction to Programming Using Java.
    Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor

  4. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,800
    Rep Power
    25

    Default

    java.util.Enumeration<String> paramNames = (java.util.Enumeration<String>) request.getParameterNames();
    I don't see the above in your posted code. You're changing the target.
    he jar file that the IDE is using was not built using Generics
    The jar I compiled with was servlet-api.jar from Tomcat 5.5 in the common/lib/ folder. I agree, it's not with generics.

    Only solution to keep from getting warnings is the old way, cast, cast, cast

  5. #5
    Nicholas Jordan's Avatar
    Nicholas Jordan is offline Senior Member
    Join Date
    Jun 2008
    Location
    Southwest
    Posts
    1,018
    Rep Power
    8

    Default declaration provided

    Quote Originally Posted by Norm View Post
    I don't see the above in your posted code. You're changing the target.
    Java Code:
    java.util.Enumeration<String> paramNames = (java.util.Enumeration<String>) request.getParameterNames();
    the while loop feeds this.
    Quote Originally Posted by Norm View Post
    The jar I compiled with was servlet-api.jar from Tomcat 5.5 in the common/lib/ folder. I agree, it's not with generics.
    So what's the fix?..replace the dot jar in NetBeans?
    Quote Originally Posted by Norm View Post
    Only solution to keep from getting warnings is the old way, cast, cast, cast
    I put that in as soon as I saw the compiler message, no change in diagnostic. I just ran update IDE, appears will have no effect.
    Introduction to Programming Using Java.
    Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor

Similar Threads

  1. Help w/ generics
    By Hollywood in forum New To Java
    Replies: 2
    Last Post: 02-16-2008, 04:08 AM
  2. Generics
    By sireesha in forum New To Java
    Replies: 2
    Last Post: 01-11-2008, 12:08 AM
  3. Generics
    By eva in forum New To Java
    Replies: 2
    Last Post: 01-04-2008, 10:10 PM
  4. Java confused over Generics?
    By Bibendum in forum New To Java
    Replies: 3
    Last Post: 12-26-2007, 07:23 AM

Posting Permissions

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