Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: How do i fix "ActionListener cannot be resolved to a type" in Eclipse?

  1. #1
    Junior Member
    Join Date
    Apr 2023
    Fier, Albania
    Thanked 0 Times in 0 Posts

    Exclamation How do i fix "ActionListener cannot be resolved to a type" in Eclipse?

    I'm using Eclipse to build a version of....notepad. However, i always get stuck on the ActionListener for the button for creating a tab. Here:

    package com.Marko2155.BetterNotepad;

    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;

    import javax.swing.*;

    class MainProgram{
    public static void main(String[] args) {
    JFrame frame = new JFrame();
    JButton button = new JButton("Click here to add a tab");
    JTabbedPane tabs = new JTabbedPane();
    JTextArea field = new JTextArea();

    //Add component settings here
    //ActionListener cannot be resolved to a variable
    ActionListener listener = new ActionListener(){
    public void actionPerformed(ActionEvent e) {

    //Add manual tabs here
    tabs.addTab("+", button);
    //Add components here
    //Window settings here
    frame.setLayout(new BoxLayout(frame.getContentPane(), BoxLayout.Y_AXIS));
    frame.setSize(800, 600);

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Eastern Florida
    Thanked 2,708 Times in 2,658 Posts

    Default Re: How do i fix "ActionListener cannot be resolved to a type" in Eclipse?

    Can you copy and paste here the full text of the error message?

    Please edit your post and wrap your code with code tags:


    to get highlighting and preserve formatting.

    There are lots of examples of working code on the site if you search for ActionListener.
    Basically do not try to declare a variable that is an instance of ActionListener.
    Just use new to create an instance of ActionListener.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Replies: 4
    Last Post: July 18th, 2014, 02:04 AM
  2. Replies: 1
    Last Post: July 16th, 2014, 04:16 AM
  3. Getting error as "cannot be resolved to a type"
    By Prince76 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 7th, 2013, 07:18 AM
  4. Error message "Type result cannot be resolved or is not a field"
    By asreall in forum What's Wrong With My Code?
    Replies: 1
    Last Post: December 28th, 2012, 08:40 AM
  5. "The import ___ cannot be resolved" (stupid noob question)
    By RobG in forum What's Wrong With My Code?
    Replies: 2
    Last Post: December 18th, 2010, 03:09 PM