Java可以找不到符号

Java可以找不到符号

本文介绍了Java可以找不到符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的错误信息

  test.java:17:找不到符号
符号:类MouseAdapter
位置:类测试
        私有类点击扩展MouseAdapter
                                    ^
test.java:19:找不到符号
符号:类的MouseEvent
位置:类test.click
                公共无效的mouseEntered(的MouseEvent E)
                                         ^
test.java:14:找不到符号
符号:变量托盘图标
位置:类测试
        trayicon.addMouseListener(新点击());
        ^
3个错误


 进口的javax.swing *。
javax.swing.event中导入*。
进口java.awt中的*。公共类测试扩展的JFrame
{    私人的JFrame框架;    公共无效的init()
    {
        trayicon.addMouseListener(新点击());
    }        私有类点击扩展MouseAdapter
        {
            公共无效的mouseEntered(的MouseEvent E)
            {
                {
                frame.setVisible(真);
            }
        }
    }
}


解决方案

重现错误:

  $猫> test.java<&LT ;.
进口的javax.swing *。
javax.swing.event中导入*。
进口java.awt中的*。公共类测试扩展的JFrame
{    私人的JFrame框架;    公共无效的init()
    {
        trayicon.addMouseListener(新点击());
    }        私有类点击扩展MouseAdapter
        {
            公共无效的mouseEntered(的MouseEvent E)
            {
                {
                frame.setVisible(真);
            }
        }
    }
}

$ javac的test.java
test.java:15:找不到符号
符号:类MouseAdapter
位置:类测试
        私有类点击扩展MouseAdapter
                                    ^
test.java:17:找不到符号
符号:类的MouseEvent
位置:类test.click
            公共无效的mouseEntered(的MouseEvent E)
                                     ^
test.java:12:找不到符号
符号:变量托盘图标
位置:类测试
        trayicon.addMouseListener(新点击());
        ^
3个错误

添加导入

  $ ED test.java
431
1I
java.awt.event中导入*。

WQ
456
$ javac的test.java
test.java:13:找不到符号
符号:变量托盘图标
位置:类测试
        trayicon.addMouseListener(新点击());
        ^
1个错误

声明托盘图标第13行

  $ ED test.java
456
13I
        JLabel的托盘图标=新的JLabel(); //或者一些有意义

WQ
528
$ javac的test.java
$

修正了!

致使code:

  $猫test.java
java.awt.event中导入*。
进口的javax.swing *。
javax.swing.event中导入*。
进口java.awt中的*。公共类测试扩展的JFrame
{    私人的JFrame框架;    公共无效的init()
    {
        JLabel的托盘图标=新的JLabel(); //或者一些有意义
        trayicon.addMouseListener(新点击());
    }        私有类点击扩展MouseAdapter
        {
            公共无效的mouseEntered(的MouseEvent E)
            {
                {
                frame.setVisible(真);
            }
        }
    }
}

BTW,你不需要线26和21:

  $ ED test.java
633
26D
21D
WQ
605
$ javac的test.java
$
$猫test.java
java.awt.event中导入*。
进口的javax.swing *。
javax.swing.event中导入*。
进口java.awt中的*。公共类测试扩展的JFrame
{    私人的JFrame框架;    公共无效的init()
    {
        JLabel的托盘图标=新的JLabel(); //或者一些有意义
        trayicon.addMouseListener(新点击());
    }        私有类点击扩展MouseAdapter
        {
            公共无效的mouseEntered(的MouseEvent E)
            {
                frame.setVisible(真);
            }
        }
    }

This is my error message

test.java:17: cannot find symbol
symbol  : class MouseAdapter
location: class test
        private class click extends MouseAdapter
                                    ^
test.java:19: cannot find symbol
symbol  : class MouseEvent
location: class test.click
                public void mouseEntered(MouseEvent e)
                                         ^
test.java:14: cannot find symbol
symbol  : variable trayicon
location: class test
        trayicon.addMouseListener(new click());
        ^
3 errors


import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;

public class test extends JFrame
{

    private JFrame frame;

    public void init()
    {
        trayicon.addMouseListener(new click());
    }

        private class click extends MouseAdapter
        {
            public void mouseEntered(MouseEvent e)
            {
                {
                frame.setVisible(true);
            }
        }
    }
}
解决方案

Reproducing the error:

$cat >test.java <<.
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;

public class test extends JFrame
{

    private JFrame frame;

    public void init()
    {
        trayicon.addMouseListener(new click());
    }

        private class click extends MouseAdapter
        {
            public void mouseEntered(MouseEvent e)
            {
                {
                frame.setVisible(true);
            }
        }
    }
}
.
$javac test.java
test.java:15: cannot find symbol
symbol  : class MouseAdapter
location: class test
        private class click extends MouseAdapter
                                    ^
test.java:17: cannot find symbol
symbol  : class MouseEvent
location: class test.click
            public void mouseEntered(MouseEvent e)
                                     ^
test.java:12: cannot find symbol
symbol  : variable trayicon
location: class test
        trayicon.addMouseListener(new click());
        ^
3 errors

Adding the import

$ed test.java
431
1i
import java.awt.event.*;
.
wq
456
$javac test.java
test.java:13: cannot find symbol
symbol  : variable trayicon
location: class test
        trayicon.addMouseListener(new click());
        ^
1 error

Declaring trayicon at line 13

$ed test.java
456
13i
        JLabel trayicon = new JLabel();// or something that makes sense
.
wq
528
$javac test.java
$

Fixed!

Resulting code:

$cat test.java
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;

public class test extends JFrame
{

    private JFrame frame;

    public void init()
    {
        JLabel trayicon = new JLabel();// or something that makes sense
        trayicon.addMouseListener(new click());
    }

        private class click extends MouseAdapter
        {
            public void mouseEntered(MouseEvent e)
            {
                {
                frame.setVisible(true);
            }
        }
    }
}

BTW, you don't need lines 26 and 21:

$ed test.java
633
26d
21d
wq
605
$javac test.java
$
$cat test.java
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;

public class test extends JFrame
{

    private JFrame frame;

    public void init()
    {
        JLabel trayicon = new JLabel();// or something that makes sense
        trayicon.addMouseListener(new click());
    }

        private class click extends MouseAdapter
        {
            public void mouseEntered(MouseEvent e)
            {
                frame.setVisible(true);
            }
        }
    }

这篇关于Java可以找不到符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-07 04:03