Java的:ArrayList都找不到符号 [英] Java: ArrayList cannot find symbol

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

问题描述

我工作的机器人迷宫其中机器人发现目标没有撞上墙壁。我知道我错过了一些东西,或做了一些错误的(最有可能是两件事情,哈哈),但我一直在货架我的大脑在它的几个小时,试了几个备选方案。我是pretty肯定我的错误或者是在哪里以及如何申报的ArrayList

任何帮助是AP preciated :)

我会发布编译错误消息的图片,但我没有10分的声誉。从本质上讲,有10个错误消息说,它不能找到该符号的 passageDirections nonwallDirections

PS:我是初学者程序员,仍然在学习这样解释你的答案,如果你要解释给一个三岁的:)

 


解决方案

passageDirections 变量是本地的 passageExits 方法。你不能从其他方法来访问它。

如果你想从你的类的所有方法访问它,使它的一个实例变量。

这同样适用于 nonwallDirections 这是本地 nonwallExits 方法。

 公共类Explorer2 {
    ...
    私人的ArrayList<整数GT; nonwallDirections =新的ArrayList<整数GT;();
    私人的ArrayList<整数GT; passageDirections =新的ArrayList<整数GT;();
    ...
}

I am working on a Robot Maze where the robot finds the target without crashing into walls. I know I've missed something or done something incorrectly (most likely a couple of things haha) but I've been racking my brain over it for a couple of hours now and tried several alternatives. I’m pretty sure my error is either where and how I declared the ArrayList.

Any help is appreciated :)

I would post a picture of the compiling error messages but I do not have 10 reputation points. Essentially, there are 10 error messages saying it cannot find the symbol for the passageDirections and nonwallDirections.

PS: I am a beginner programmer, still learning so explain your answer as if you were to explain it to a three year old :)

i

解决方案

Your passageDirections variable is local to your passageExits method. You can't access it from other methods.

If you want to access it from all methods of your class, make it an instance variable.

The same applies to nonwallDirections which is local to nonwallExits method.

public class Explorer2 {
    ...
    private ArrayList<Integer> nonwallDirections = new ArrayList<Integer>();
    private ArrayList<Integer> passageDirections = new ArrayList<Integer>();
    ...
}

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆