Incompatible Types error

Posted on 2008-11-14
Last Modified: 2012-05-05
I am using the following piece of code in a JHTML file and getting errors.

                  Double pInterest = (Double) request.getObjectParameter("element.primaryInterest");

                  switch (pInterest){
                  case 7 :
                        <span class="strong_red"> Test</span>&nbsp;&nbsp;&nbsp;
                        ; break; }


Error: Error compiling page: /web/gears/whatsnewgear/whatsnewgearshared.jhtml : E:\ATG\ATG2006.3\home\pagebuild\_doc_3\_web\_gears\_whatsnewgear\ incompatible types
      found   : java.lang.Double
      required: int

If i change the type to Int as the following

                  Int pInterest = (Int) request.getObjectParameter("element.primaryInterest");

                  switch (pInterest){
                  case 7 :
                        <span class="strong_red"> Test</span>&nbsp;&nbsp;&nbsp;
                        ; break; }

Error: Caused by :atg.servlet.pagecompile.AutoCompileException: E:\ATG\ATG2006.3\home\pagebuild\_doc_3\_web\_gears\_whatsnewgear\ cannot resolve symbol
      symbol  : class Int
      location: class _doc_3._web._gears._whatsnewgear._whatsnewgearshared._Param_0_output
                        Int pInterest = (Int) request.getObjectParameter("element.primaryInterest");

Would appreciate any help

Question by:qhinds
    LVL 86

    Accepted Solution

    Should be
     int pInterest = (int) request.getObjectParameter("element.primaryInterest");

    Open in new window


    Expert Comment

    if you are using java 5.x or later you can cast the getObjectParameter result to int just as CEHJ has write,
    but to be compatible with older jvms, you can Cast the result to Integer Object and then get its int value:
    int pInterest = ((Integer) request.getObjectParameter("element.primaryInterest")).intValue() ;

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    Suggested Solutions

    Title # Comments Views Activity
    Which XML parser should I used for my requirement 11 48
    scoreUp challenge 14 40
    commonTwo  challenge 63 68
    noX challenge 17 52
    Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
    Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
    Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
    Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now