Results 1 to 12 of 12
- 07-20-2011, 08:48 PM #1
Senior Member
- Join Date
- Jul 2011
- Posts
- 100
- Rep Power
- 0
The Compiler is conspiring to drive me madder than a Hatfield &&|| McCoy
I have an event handler for a button:
...that elicits this scornful diatribe from the compiler: "Illegal modifier for the local class OpenDispatchFileButtonListener; only abstract or final is permitted"Java Code:public class OpenDispatchFileButtonListener implements ActionListener { @Override public void actionPerformed(ActionEvent e) { ...
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)
- 07-20-2011, 09:13 PM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,406
- Blog Entries
- 7
- Rep Power
- 17
Did you define that class inside the body of a method?
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 07-20-2011, 09:32 PM #3
Senior Member
- Join Date
- Jul 2011
- Posts
- 100
- Rep Power
- 0
The code causing the error:
...is in "public void go()", which is called by:Java Code:btnOpenDispatchFile.addActionListener(new OpenDispatchFileButtonListener());
OpenDispatchFileButtonListener() is an inner class only of the file's main/outermost class:Java Code:public static void main(String[] args) { new RT_TCP_JCP_TDS_OO_State_SortSim().go(); }
The four err msgs I'm getting now are:Java Code:import java.awt.event.*; public class RT_TCP_JCP_TDS_OO_State_SortSim { ... private class OpenDispatchFileButtonListener implements ActionListener {
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.
-
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.
- 07-21-2011, 09:50 AM #5
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
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.
- 07-21-2011, 10:33 AM #6
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,547
- Rep Power
- 11
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).
- 07-21-2011, 05:11 PM #7
Senior Member
- Join Date
- Jul 2011
- Posts
- 100
- Rep Power
- 0
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 { ... } ... }
- 07-21-2011, 05:21 PM #8
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; ^
- 07-21-2011, 05:46 PM #9
Senior Member
- Join Date
- Jul 2011
- Posts
- 100
- Rep Power
- 0
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.
- 07-21-2011, 06:29 PM #10
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,406
- Blog Entries
- 7
- Rep Power
- 17
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,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 07-21-2011, 07:05 PM #11
Senior Member
- Join Date
- Jul 2011
- Posts
- 100
- Rep Power
- 0
- 07-21-2011, 08:00 PM #12
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,406
- Blog Entries
- 7
- Rep Power
- 17
Similar Threads
-
Best way to format a drive/thumb drive in java...
By vandyke in forum Advanced JavaReplies: 1Last Post: 12-09-2009, 01:32 AM -
jvm on flash drive
By kabinet in forum New To JavaReplies: 4Last Post: 11-02-2009, 07:38 AM -
compiler,JIT compiler & interpreter
By gamilah in forum New To JavaReplies: 4Last Post: 11-04-2008, 12:32 AM -
Drive names
By alwz_nikhil in forum New To JavaReplies: 0Last Post: 11-28-2007, 10:04 AM -
access cd drive
By milinkp in forum New To JavaReplies: 0Last Post: 07-20-2007, 06:14 AM


7Likes
LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks