Solved

Compiling error

Posted on 2004-10-16
16
195 Views
Last Modified: 2013-12-03
Choice font = new Choice();      
      for ( int i = 0; i < fontList.length; i++ )
       {
      add(font);
      font.addActionListener(this);
      font.addItem(fontList[i]);
      font.setBackground(Color.lightGray);
      }

      public void actionPerformed(ActionEvent e) {
             if (e.getSource() instanceof Choice) {
                 String choice = (String) e.getSelectedItem();
                 editorPane.setFont( new Font( choice,Font.ITALIC,10) );
            }
      }


Error:
cannot resolve symbol
method addActionListener()
class java.awt.Choice
>> font.addActionListener(this);

Error:
cannot resolve symbol
method getSelectedItem()
class java.awt.event.ActionEvent
>>  String choice = (String) e.getSelectedItem();

-------------------------------------------------------------------

Any expert please help me to debug this code.
0
Comment
Question by:tloip
  • 8
  • 3
  • 3
  • +1
16 Comments
 
LVL 24

Expert Comment

by:sciuriware
ID: 12331432
Obviously Choice has no method 'addActionListener()'.
Ditto ActionEvent has no method 'getSelectedItem()'.
Please refer to the JAVADOC for the methods that exist for those classes.
;JOOP!
0
 
LVL 21

Assisted Solution

by:MogalManic
MogalManic earned 30 total points
ID: 12332050
Is this what you want?

            Choice font = new Choice();
            for (int i = 0; i < fontList.length; i++) {
                  add(font);
                  font.addInputMethodListener(this);
                  font.addItem(fontList[i]);
                  font.setBackground(Color.lightGray);
            }
      }


      public void actionPerformed(ActionEvent e) {
            if (e.getSource() instanceof Choice) {
                  String choice = (String) e.getActionCommand();
                  editorPane.setFont(new Font(choice, Font.ITALIC, 10));
            }
      }
0
 

Author Comment

by:tloip
ID: 12332118
what do u mean no method?
can u specify it?
0
 
LVL 24

Expert Comment

by:sciuriware
ID: 12332130
The methods you wrote down do not exist for those classes.
;JOOP!
0
 

Author Comment

by:tloip
ID: 12332145
an error occurred:

addInputMethodListener(java.awt.event.InputMethodListener) in java.awt.Component cannot be applied to (gui)

> font.addInputMethodListener(this)
0
 

Author Comment

by:tloip
ID: 12332205
doesn't exist?
So do i need to modify my code or just add code to it?

0
 
LVL 24

Expert Comment

by:sciuriware
ID: 12333246
If you think that Choice can have an actionListener ... read the JAVADOC.
;JOOP!
0
 
LVL 21

Expert Comment

by:MogalManic
ID: 12333312
What do you want to accomplish?  

The Font class does NOT have an actionListener event.  It DOES have an inputMethod listener event.  Read the javadoc for the Font class and the Choice class.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 1

Expert Comment

by:Celdric
ID: 12335244
I think we need to see which libraries are you importing and if those classes are where
they are supposed to be regardless of method use, the error is because it
cant find the class, not an invalid method.

Also, it will be helpful if you tell us in which plataform are you coding...
Netbeans, Eclipse? Are you trying to make a webapp? an applet?

and MogalManic is correct

addInputMethodListener(java.awt.event.InputMethodListener) in java.awt.Component cannot be applied to (gui)
> font.addInputMethodListener(this)

This means that you cant attach a InputMethodListener to a GUI object.

We need more info here..
0
 

Author Comment

by:tloip
ID: 12336638
i'm using dos platform (j2sdk1.4.2_04).
this is one part of my program.
This part allows user to select the font face being used display the message (typed in textfield) in editorpane.

i imported these:

/* * My GUI Client */
import javax.swing.*;
import javax.swing.text.*;
import java.awt.*;
//for HTML Headers
import javax.swing.text.StyledEditorKit.*;
import javax.swing.text.html.HTMLEditorKit.*;
import javax.swing.text.html.*;
import javax.swing.event.HyperlinkListener;
import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkEvent.EventType;
import javax.swing.text.html.HTMLFrameHyperlinkEvent;
//for layout managers
import java.awt.event.*;
//for action and window events
import java.io.*;
import java.net.*;
import java.awt.GraphicsEnvironment;
0
 
LVL 1

Expert Comment

by:Celdric
ID: 12337922
Ah, now I think thats your problem, you see, (Well, in my case, I dont know if its by default)
Well, whenever I use only the command line to code, I have to manually
direct the jdk to the libraries.

So, no matter if you declare the imports in your java file, the JDK wont find it until you
point it to the right jar or libraries outside the file...heres an example:

This class uses the openjms library, although I declare it inside the java file, I still need
to tell the JDK where those imports are, this is done with the -classpath option.

Java -classpath c:\myJ2EEjdk\lib\openjms.jar com.softtek.mypackage.MyClass

The syntax is: Java -classpath <library location> <class package>

If still in doubt, I recommend you learn to use either Netbeans or MyEclipse they do all this
for you, and they are both great coding plataforms, plenty of info out there too.

Oh! Remember to have your enviromental variables set, JAVA_HOME is very important

Hope this helped.
0
 

Author Comment

by:tloip
ID: 12346087
I have NetBean as well but i really no idea on how to run the file.
I'm running the server...something like i will type like this :
>>>    java gui 127.0.0.2 2222
I need to run 3 files at one go to run my program.

Is it the problem occured on what platform i'm using and isn't because the code problem?
0
 

Author Comment

by:tloip
ID: 12346098
usually before i run my file..I might type..

>>>  path=C:\jsdk1.4.2_04\bin

0
 
LVL 1

Accepted Solution

by:
Celdric earned 20 total points
ID: 12346475
Well, since you do include the jdk in your path, i guess you include the neccesary libraries..

Well, like they have said b4..this error:
Error:
cannot resolve symbol
method getSelectedItem()
class java.awt.event.ActionEvent

means thats the ActionEvent does not have a getSelectedItem method and its right:

http://java.sun.com/j2se/1.3/docs/api/java/awt/event/ActionEvent.html

That is the specification for the class ActionEvent, and there it is listed all methods that
are implemented within the class and inherited from others.
getSelectedItem is not one of them.

as for the choice class:
http://java.sun.com/j2se/1.3/docs/api/java/awt/Choice.html
it doesnt have an addActionListener either, although it has like 4 different listeners
ActionListener isnt one of them.

Sorry to say, you got to find different methods to implement your application.

Good luck

0
 

Author Comment

by:tloip
ID: 12355044
Ok, thanks for giving comment. I can solve it with your guidance.
0
 

Author Comment

by:tloip
ID: 12366755
I did that..I'm not sure correct or not but it doesn't work. Means didn't show the message in selected font face.

public void itemStateChanged(ItemEvent e) {
             if (e.getSource() instanceof Choice) {
                  String choice = (String) e.getItem();
                  editorPane.setFont( new Font( choice,Font.PLAIN,10 ) );
            }
      }
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

947 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

20 Experts available now in Live!

Get 1:1 Help Now