11 Replies Latest reply: Mar 21, 2013 12:53 AM by EJP RSS

    Unable to declare it

    HuaMin Chen
      Hi,
      why do I get this

      Error: Compile Error: Illegal modifier on local variable at line 3 column 15

      due to this?
      public string message;
        • 1. Re: Unable to declare it
          EJP
          Java is case-sensitive. Try 'String'.
          • 2. Re: Unable to declare it
            HuaMin Chen
            Yes, get the same
                 Error: Compile Error: Illegal modifier on local variable at line 3 column 15

            to
            public String message;
            • 3. Re: Unable to declare it
              rp0428
              If you want help you need to post the code; not just one line of it.
              • 4. Re: Unable to declare it
                EJP
                Yes, get the same
                     Error: Compile Error: Illegal modifier on local variable at line 3 column 15
                So remove 'public'. You can't have that modifier on a local variable. The compiler has already told you that.
                • 5. Re: Unable to declare it
                  HuaMin Chen
                  Yes, here are the codes:

                  1     public class StoreFront {
                  2     public PageReference shop() {
                  3     public String message;
                  4     message = 'You bought: ';
                  5     for (DisplayMerchandise p: products) {
                  6     if (p.count > 0) {
                  7     message += p.merchandise.name + ' (' + p.count + ') ';
                  8     }
                  9     }
                  10     return null;
                  11     }
                  ...

                  and here is the error
                  Error: Compile Error: Illegal modifier on local variable at line 3 column 15
                  • 6. Re: Unable to declare it
                    HuaMin Chen
                    If I remove "public", I get

                    Error     Error: Compile Error: The property String message is referenced by Visualforce Page (StoreFront) in salesforce.com. Remove the usage and try again. at line 3 column 19
                    • 7. Re: Unable to declare it
                      EJP
                      That's not your real code, because of all the single quotes. When I fix that I don't get any compile error. NB surely you mean to return 'message' rather than 'null'?
                      • 8. Re: Unable to declare it
                        HuaMin Chen
                        Those are the codes that I put.
                        • 9. Re: Unable to declare it
                          EJP
                          No. It doesn't compile. QED. You have string literals in single quotes, and string literals are bounded by double quotes in Java. When you post code here, cut and paste it, don't retype it. Cannot reproduce your problem. At this stage this is not a real question.
                          • 10. Re: Unable to declare it
                            HuaMin Chen
                            Those are really the codes I have in the class. But I thought the codes of Salesforce probably are not reall Java codes!
                            • 11. Re: Unable to declare it
                              EJP
                              No they are not really the 'codes' you have in the class. Proof 1:
                              C:\Documents and Settings\ejp\Tests\src\StoreFront.java:10: class, interface, or enum expected
                              1 public class StoreFront {
                              C:\Documents and Settings\ejp\Tests\src\StoreFront.java:11: illegal start of type
                              2 public PageReference shop() {
                              C:\Documents and Settings\ejp\Tests\src\StoreFront.java:11: ';' expected
                              2 public PageReference shop() {
                              C:\Documents and Settings\ejp\Tests\src\StoreFront.java:12: not a statement
                              3 public String message;
                              C:\Documents and Settings\ejp\Tests\src\StoreFront.java:12: ';' expected
                              3 public String message;
                              C:\Documents and Settings\ejp\Tests\src\StoreFront.java:12: illegal start of expression
                              3 public String message;
                              C:\Documents and Settings\ejp\Tests\src\StoreFront.java:12: ';' expected
                              3 public String message;
                              C:\Documents and Settings\ejp\Tests\src\StoreFront.java:12: not a statement
                              3 public String message;
                              C:\Documents and Settings\ejp\Tests\src\StoreFront.java:13: not a statement
                              4 message = 'You bought: ';
                              C:\Documents and Settings\ejp\Tests\src\StoreFront.java:13: ';' expected
                              4 message = 'You bought: ';
                              C:\Documents and Settings\ejp\Tests\src\StoreFront.java:13: unclosed character literal
                              4 message = 'You bought: ';
                              C:\Documents and Settings\ejp\Tests\src\StoreFront.java:13: ';' expected
                              4 message = 'You bought: ';
                              C:\Documents and Settings\ejp\Tests\src\StoreFront.java:13: unclosed character literal
                              4 message = 'You bought: ';
                              C:\Documents and Settings\ejp\Tests\src\StoreFront.java:15: not a statement
                              6 if (p.count > 0) {
                              C:\Documents and Settings\ejp\Tests\src\StoreFront.java:15: ';' expected
                              6 if (p.count > 0) {
                              C:\Documents and Settings\ejp\Tests\src\StoreFront.java:16: not a statement
                              7 message += p.merchandise.name + ' (' + p.count + ') ';
                              C:\Documents and Settings\ejp\Tests\src\StoreFront.java:16: ';' expected
                              7 message += p.merchandise.name + ' (' + p.count + ') ';
                              C:\Documents and Settings\ejp\Tests\src\StoreFront.java:16: unclosed character literal
                              7 message += p.merchandise.name + ' (' + p.count + ') ';
                              C:\Documents and Settings\ejp\Tests\src\StoreFront.java:16: unclosed character literal
                              7 message += p.merchandise.name + ' (' + p.count + ') ';
                              C:\Documents and Settings\ejp\Tests\src\StoreFront.java:16: unclosed character literal
                              7 message += p.merchandise.name + ' (' + p.count + ') ';
                              C:\Documents and Settings\ejp\Tests\src\StoreFront.java:16: not a statement
                              7 message += p.merchandise.name + ' (' + p.count + ') ';
                              C:\Documents and Settings\ejp\Tests\src\StoreFront.java:16: unclosed character literal
                              7 message += p.merchandise.name + ' (' + p.count + ') ';
                              C:\Documents and Settings\ejp\Tests\src\StoreFront.java:16: ';' expected
                              7 message += p.merchandise.name + ' (' + p.count + ') ';
                              C:\Documents and Settings\ejp\Tests\src\StoreFront.java:18: not a statement
                              9 }
                              C:\Documents and Settings\ejp\Tests\src\StoreFront.java:18: ';' expected
                              9 }
                              C:\Documents and Settings\ejp\Tests\src\StoreFront.java:19: not a statement
                              10 return null;
                              C:\Documents and Settings\ejp\Tests\src\StoreFront.java:19: ';' expected
                              10 return null;
                              C:\Documents and Settings\ejp\Tests\src\StoreFront.java:20: not a statement
                              11 }
                              C:\Documents and Settings\ejp\Tests\src\StoreFront.java:20: ';' expected
                              11 }
                              C:\Documents and Settings\ejp\Tests\src\StoreFront.java:20: reached end of file while parsing
                              11 }
                              30 errors
                              If I'm kind and remove the line numbers, which are definitely not in the 'codes' in the class, it becomes this:
                              C:\Documents and Settings\ejp\Tests\src\StoreFront.java:17: illegal start of expression
                              public String message;
                              C:\Documents and Settings\ejp\Tests\src\StoreFront.java:18: unclosed character literal
                              message = 'You bought: ';
                              C:\Documents and Settings\ejp\Tests\src\StoreFront.java:18: ';' expected
                              message = 'You bought: ';
                              C:\Documents and Settings\ejp\Tests\src\StoreFront.java:18: unclosed character literal
                              message = 'You bought: ';
                              C:\Documents and Settings\ejp\Tests\src\StoreFront.java:21: unclosed character literal
                              message += p.merchandise.name + ' (' + p.count + ') ';
                              C:\Documents and Settings\ejp\Tests\src\StoreFront.java:21: unclosed character literal
                              message += p.merchandise.name + ' (' + p.count + ') ';
                              C:\Documents and Settings\ejp\Tests\src\StoreFront.java:21: unclosed character literal
                              message += p.merchandise.name + ' (' + p.count + ') ';
                              C:\Documents and Settings\ejp\Tests\src\StoreFront.java:21: not a statement
                              message += p.merchandise.name + ' (' + p.count + ') ';
                              C:\Documents and Settings\ejp\Tests\src\StoreFront.java:21: unclosed character literal
                              message += p.merchandise.name + ' (' + p.count + ') ';
                              C:\Documents and Settings\ejp\Tests\src\StoreFront.java:21: ';' expected
                              message += p.merchandise.name + ' (' + p.count + ') ';
                              C:\Documents and Settings\ejp\Tests\src\StoreFront.java:25: reached end of file while parsing
                               }
                              11 errors
                              Please stop arguing about this, it's completely pointless. If it isn't Java code you're asking in the wrong place anyway.