Results 1 to 12 of 12
Like Tree7Likes
  • 1 Post By JosAH
  • 1 Post By Fubarable
  • 1 Post By Tolls
  • 1 Post By pbrockway2
  • 1 Post By Norm
  • 1 Post By JosAH
  • 1 Post By JosAH

Thread: The Compiler is conspiring to drive me madder than a Hatfield &&|| McCoy

  1. #1
    blackbird is offline Senior Member
    Join Date
    Jul 2011
    Posts
    100
    Rep Power
    0

    Default The Compiler is conspiring to drive me madder than a Hatfield &&|| McCoy

    I have an event handler for a button:

    Java Code:
    public class OpenDispatchFileButtonListener implements ActionListener {
      @Override
      public void actionPerformed(ActionEvent e) {
        ...
    ...that elicits this scornful diatribe from the compiler: "Illegal modifier for the local class OpenDispatchFileButtonListener; only abstract or final is permitted"

    If I change the "public" to "final", I get: "OpenDispatchFileButtonListener cannot be resolved to a type" on this line of code:

    Java Code:
    btnOpenDispatchFile	.addActionListener(new OpenDispatchFileButtonListener());
    Last edited by blackbird; 07-20-2011 at 08:49 PM. Reason: the formatting looked like Dallas (superfluous crlf)

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,433
    Blog Entries
    7
    Rep Power
    20

    Default

    Did you define that class inside the body of a method?

    kind regards,

    Jos
    blackbird likes this.
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    blackbird is offline Senior Member
    Join Date
    Jul 2011
    Posts
    100
    Rep Power
    0

    Default

    Quote Originally Posted by JosAH View Post
    Did you define that class inside the body of a method?

    kind regards,

    Jos
    The code causing the error:

    Java Code:
    btnOpenDispatchFile.addActionListener(new OpenDispatchFileButtonListener());
    ...is in "public void go()", which is called by:

    Java Code:
    public static void main(String[] args) {
      new RT_TCP_JCP_TDS_OO_State_SortSim().go();
    }
    OpenDispatchFileButtonListener() is an inner class only of the file's main/outermost class:

    Java Code:
    import java.awt.event.*;
    
    public class RT_TCP_JCP_TDS_OO_State_SortSim {
    
    ...
    
    private class OpenDispatchFileButtonListener implements ActionListener {
    The four err msgs I'm getting now are:
    1) OpenDispatchFileButonListener cannot be resolved to a type
    2) OpenDispositionFileButonListener cannot be resolved to a type
    3) Project 'bla' is missing required source folder: 'src'
    4) The project cannot be built until build path errors are resolved

    #3 is not true - there is a 'src' folder, under which the file generating these errors lives.

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Reduce your code to the smallest possible code that shows the error, something that hopefully won't be more than 40-50 lines long, and post it here.
    blackbird likes this.

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,931
    Rep Power
    19

    Default

    You sure you've not got a typo?
    OpenDispatchFileButonListener in the error message
    OpenDispatchFileButtonListener in your code

    But, if the project is complaining about some paths then I'd go and check the project setup. Check the src folder is correctly declared as a source folder, check your output folder is declared correctly and, finally, the build path.
    blackbird likes this.

  6. #6
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    Also Jos was talking about where you defined the class ("public class OpenDispatchFileButtonListener implements ActionListener { etc") not where you used addActionListener().

    Almost certainly you shouldn't define the class within a method. In any case, if you do then it can't be public, and it can't be accessed from any other method (or block).
    blackbird likes this.

  7. #7
    blackbird is offline Senior Member
    Join Date
    Jul 2011
    Posts
    100
    Rep Power
    0

    Default

    Quote Originally Posted by pbrockway2 View Post
    Also Jos was talking about where you defined the class ("public class OpenDispatchFileButtonListener implements ActionListener { etc") not where you used addActionListener().

    Almost certainly you shouldn't define the class within a method. In any case, if you do then it can't be public, and it can't be accessed from any other method (or block).
    Yes, I thought I answered that. It's a separate class within/below public class RT_TCP_JCP_TDS_OO_State_SortSim { (the outermost class, which begins right after the "imports" statements and whose ending "}" is the last character in the file).

    IOW, I have:
    Java Code:
    public class RT_TCP_JCP_TDS_OO_State_SortSim {
    ...
      public class OpenDispatchFileButtonListener implements ActionListener {
        ...
      }
    ...
    }

  8. #8
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,308
    Rep Power
    25

    Default

    Have you ever posted the FULL text of the error message?
    Here is a sample:
    Java Code:
    TestSorts.java:138: cannot find symbol
    symbol  : variable var
    location: class TestSorts
             var = 2;
             ^
    blackbird likes this.

  9. #9
    blackbird is offline Senior Member
    Join Date
    Jul 2011
    Posts
    100
    Rep Power
    0

    Default

    I found the problem when comparing an ActionListener that was "sliding by" without any squawks - what was different about it, where it was accepted and the other was not. It turns out that the "good" one was actually the bad one - it was missing a "}"; once I added that there, and removed one from the end of the file, all is hunky dory.

  10. #10
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,433
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by blackbird View Post
    I found the problem when comparing an ActionListener that was "sliding by" without any squawks - what was different about it, where it was accepted and the other was not. It turns out that the "good" one was actually the bad one - it was missing a "}"; once I added that there, and removed one from the end of the file, all is hunky dory.
    That is strange; if your (first) inner class is missing a last } everything else ends up as a member of that inner class but then your other }s are goofy at the end of your outer class. I do hope everything is really "hunky dory" now, instead of just compiler error free ...

    kind regards,

    Jos
    blackbird likes this.
    cenosillicaphobia: the fear for an empty beer glass

  11. #11
    blackbird is offline Senior Member
    Join Date
    Jul 2011
    Posts
    100
    Rep Power
    0

    Default

    Quote Originally Posted by JosAH View Post
    That is strange; if your (first) inner class is missing a last } everything else ends up as a member of that inner class but then your other }s are goofy at the end of your outer class. I do hope everything is really "hunky dory" now, instead of just compiler error free ...

    kind regards,

    Jos
    I think I lied - actually, it was the other way around: there was one too many "}" in the inner class, and then I had to add one at the end.

  12. #12
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,433
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by blackbird View Post
    I think I lied - actually, it was the other way around: there was one too many "}" in the inner class, and then I had to add one at the end.
    Oh well, we can't tell without seeing the actual code; glad you got it fixed though.

    kind regards,

    Jos
    blackbird likes this.
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Best way to format a drive/thumb drive in java...
    By vandyke in forum Advanced Java
    Replies: 1
    Last Post: 12-09-2009, 01:32 AM
  2. jvm on flash drive
    By kabinet in forum New To Java
    Replies: 4
    Last Post: 11-02-2009, 07:38 AM
  3. compiler,JIT compiler & interpreter
    By gamilah in forum New To Java
    Replies: 4
    Last Post: 11-04-2008, 12:32 AM
  4. Drive names
    By alwz_nikhil in forum New To Java
    Replies: 0
    Last Post: 11-28-2007, 10:04 AM
  5. access cd drive
    By milinkp in forum New To Java
    Replies: 0
    Last Post: 07-20-2007, 06:14 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
  •