6 Replies Latest reply: Jan 23, 2008 7:00 AM by 807601 RSS

    Need help to set a string value using a setmethod if condition is true

    807601
      I am new to java and need some help. I want to set a string value called "LMP LIMITED" using a setMetho if it passed an if statement.

      I have two files called company.java and companyDetails.java

      I have the following method in company.java file
      //Sets the value of supplier
      public void setSupplier(String value) {
           data.put("supplier", value);
      }
      now in my companyDetails.java file,

      I have a if statement that checks if stupplier varified and if it is then return the name of the supplier which is LMP Limited. From the basic knowledge I have, I implemented the following code:
      if(site.getSupplierVarified() == 1) {
      company.setSupplier("LMP LIMITED");
      }
      But I get an error cannot resolve symbol method setSupplier(java.lang.String)

      Can someone plz point me in the right direction to set the string "LMP LIMITED"

      Thanks,
        • 1. Re: Need help to set a string value using a setmethod if condition is true
          PhHein
          setSupplier isn't static. company seems to be the class not an instance.
          • 2. Re: Need help to set a string value using a setmethod if condition is true
            807601
            Ah yea sorry I typed the code wrong, the instance name is companyData rather then company. Hence in companyDetails.java file I have the following code:
            companyData = new com.Company();
            
            if(site.getSupplierVarified() == 1) {
            companyData.setSupplier("LMP LIMITED");
            }
            But still i do not know how to set the string value "LMP LIMITED" if the conditional statement is true

            Thanks
            • 3. Re: Need help to set a string value using a setmethod if condition is true
              PhHein
              Then your code is borked somewhere else. It should work that way. You need to post more of your code and the complete stack trace to get a more helpful answer.
              • 4. Re: Need help to set a string value using a setmethod if condition is true
                807601
                Thanks for your reply, I have posted my full code for the both files below. Just to explain what is going on is the company java file sets fields to be placed into a pdf form.

                Here is the code for the company.java
                public class Company implements PdfForm{
                
                    private HashMap data = new HashMap();
                      private String pdfTemplateName = Constants.DEFAULT_FORM_TEMPLATE;
                
                    public Company() {
                    }    
                    /**
                     * set methods
                     */
                    public void setPdfTemplateName(String s) {
                
                        this.pdfTemplateName = s;
                    }
                    
                    /**
                     * Sets the value of address
                     */
                    public void setAddress(String value) {
                        data.put("address", value);
                    }
                
                    //Sets the value of supplier
                    public void setSupplier(String value) {
                     data.put("supplier", value);
                    }
                
                    public String getPdfTemplateName() {
                        return pdfTemplateName;
                    }
                }
                and the here is the code for the companyDetails.java
                public class CompanyDetails {
                     
                     private com.Company companyData;
                     private int applicationID = 0;
                //     private String templateName = Constants.FORM_LOCATION;
                     
                     public void setApplicationID(int i){ ID = i; }
                     
                     public void fillFormFields(){
                          companyData = new com.Company();
                         String tempAddress = "";
                         
                         com.ApplicationDetails applicationDetails = new com.ApplicationDetails();
                     applicationDetails.setApplicationID(applicationID);
                          
                     com.SiteDetails site = new com.SiteDetails();
                     site.setApplicationID(applicationID);
                         
                         if( companyData.getPdfTemplateName().equals("") ){
                     companyData.setPdfTemplateName( Constants.DEFAULT_FORM_TEMPLATE );
                     }
                          
                     companyData.setAddress(applicationDetails.getApplicantAddress());
                
                     if(site.getSupplierVarified() == 1) {
                     companyData.setSupplier("LMP LIMITED");
                     }
                
                     }
                
                     public com.Company getNewTemplateOne(){
                         return this.companyData;
                    }
                    
                }
                • 5. Re: Need help to set a string value using a setmethod if condition is true
                  PhHein
                  Ok, from what I see

                  public class Company implements PdfForm

                  is not in package com.

                  You seem to have two Company classes, and in CompanyDetails you reference com.Company which has no public void setSupplier(String value) method.
                  • 6. Re: Need help to set a string value using a setmethod if condition is true
                    807601
                    ooh ok i see what you mean, ur right I will give it a go and let you know how i get on... thanks very much for your help..

                    Regards,
                    Zub