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

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

问题描述

我正在开发一个机器人迷宫,机器人可以在不撞墙的情况下找到目标.我知道我错过了一些事情或做错了一些事情(很可能是几件事哈哈)但我已经绞尽脑汁几个小时了,并尝试了几种替代方法.我很确定我的错误在于我声明 ArrayList 的位置和方式.

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.

感谢任何帮助:)

我会发布编译错误消息的图片,但我没有 10 点声望点.基本上,有 10 条错误消息表明它找不到 passageDirectionsnonwallDirections 的符号.

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:我是一个初学者程序员,还在学习所以解释你的答案,就像你给一个三岁的孩子解释一样:)

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

推荐答案

你的 passageDirections 变量是你的 passageExits 方法的本地变量.您无法通过其他方式访问它.

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.

这同样适用于 nonwallDirections,它是 nonwallExits 方法的局部.

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天全站免登陆