- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
import java.util.*; ...
ArrayList<String> stringList = new ArrayList<String>();
stringList.add("Item");
这是我的 Java 代码。最后一行出现错误:“包 stringList 不存在”。
如何消除此错误并开始将项目添加到我的列表中?我只能想象我错过了一些非常简单的东西。提前致谢。
部分根据请求,下面是我的整个代码。它不完整,但我陷入了上述问题。
package gorobot_m5d25y2013;
//import java.util.List;
import java.util.ArrayList;
class Engine { // The Engine will show the best positions on the board given a particular board setup.
// Some project-wide constants and variables.
final int BLACK = 1; // Black go pieces... black goes first in the game of go, unless black has
// a 2 stone or greater handicap.
final int WHITE = 2; // White go pieces... usually goes second in the game.
final int EMPTY = 0; // An empty space, no piece is on it.
final int VIRTUAL = -1; // This is a space outside of the board that can never be played on,
// but is useful if there's ever an issue of checking something for
// the board which would normally be out of bounds.
final int BLACKS_TURN = 1;
final int WHITES_TURN = 2;
final int BOARD_SIZE = 19; // Access with Global.BOARD_SIZE ... this is the width of the board.
final int VIRTUAL_BOARD_BORDER = 10; // This is the width of the empty space around each of the four sides of the board.
int whoseTurn; // 1 is blacks turn, 2 is white's turn.
int totalGames = 0;
int blackWins = 0;
static long groupCounter = 1; // Used in inner class group.
int positionNumber = 1; // Used in inner class group and position.
int[][] boardValues = new int[BOARD_SIZE][BOARD_SIZE]; // boardValues is the win probability for each position on the board.
Engine() {
Board firstMove = new Board();
}
int oppositeWhoseTurn() {
int opposite = 0;
if (whoseTurn == BLACKS_TURN) {
opposite = WHITES_TURN;
}
if (whoseTurn == WHITES_TURN) {
opposite = BLACKS_TURN;
}
if (opposite == 0) {
System.out.println("An error with the opposite variable has occured.");
}
return opposite;
}
int regPos(int boardPosition) { // This Regulates Position-Ex. takes any of the normal board positions, for example,
// 1-19, and sets it to the virtual, larger board. So a Position 1 move will be position 9 with a 10 space buffer.
int realBoardPosition = (boardPosition + (VIRTUAL_BOARD_BORDER - 1));
return realBoardPosition;
}
class Board { // The board is composed of positions and groups. At first it is 2 groups, the real and the virtual
int virtualPlusRegularBoardSize = (BOARD_SIZE + (VIRTUAL_BOARD_BORDER * 2));
Position[][] point = new Position[virtualPlusRegularBoardSize][virtualPlusRegularBoardSize];
Group food = new Group();
Board() {
for (int horizontal = 0; horizontal < virtualPlusRegularBoardSize; horizontal++) {
for (int vertical = 0; vertical < virtualPlusRegularBoardSize; vertical++) {
point[horizontal][vertical] = new Position(horizontal, vertical);
}
}
for (int horizontal = 1; horizontal <= BOARD_SIZE; horizontal++) {
for (int vertical = 1; vertical <= BOARD_SIZE; vertical++) {
point[regPos(horizontal)][regPos(vertical)].setType(EMPTY);
}
}
}
}
class Group { // Each Group is composed of positions
long groupNumber;
int sizeOfGroup = 1;
Integer[] ints = new Integer[1];
ArrayList<String> stringList = new ArrayList<String>();
stringList.add ("Item");
//List<Position> positionList = new ArrayList<>();
//positionList.size ();
//positionList.add ();
//positionList.remove("F");
Group() {
groupNumber = groupCounter;
groupCounter++;
}
void setGroupNumber(int newGroupNumber) {
sizeOfGroup = newGroupNumber;
}
long getGroupNumber() {
return groupNumber;
}
void setSizeOfGroup(int newGroupSize) {
sizeOfGroup = newGroupSize;
}
int getSizeOfGroup() {
return sizeOfGroup;
}
void addPositionToGroup(Position point) {
}
}
class Position { // Each position is either Empty, Black, White, or Virtual.
int pieceType; // VIRTUAL means it's not even a board position, at first all spaces are like this...
// but eventually, the positions on the actual board will all be empty - 0, and then
// will start filling with black - 1 and white - 2 pieces.
boolean legalMove; // This tells us whether this space is a legal move.
int numberOfLiberties = 2;
int virtualHorizontal;
int virtualVertical;
Position() {
pieceType = VIRTUAL;
legalMove = false;
}
Position(int horizontal, int vertical) {
pieceType = VIRTUAL;
legalMove = true;
virtualHorizontal = horizontal;
virtualVertical = vertical;
}
void setType(int setType) {
pieceType = setType;
////// Add in here the 4 surrounding sides and make those these variables accessible from the piece class.
if (setType == BLACK) {
}
if (setType == WHITE) {
}
}
int getType() {
return pieceType;
}
}
}
/**
*
* @author Eric Martin
*/
public class GoRobot_m5d25y2013 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
Engine firstEngine = new Engine();
}
}
这些是我的错误:
run:
Exception in thread "main" java.lang.ClassFormatError: Method "<error>" in class gorobot_m5d25y2013/Engine$Group has illegal signature "(Ljava/lang/Object;)LstringList/add;"
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:791)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
at gorobot_m5d25y2013.Engine$Board.<init>(GoRobot_m5d25y2013.java:73)
at gorobot_m5d25y2013.Engine.<init>(GoRobot_m5d25y2013.java:46)
at gorobot_m5d25y2013.GoRobot_m5d25y2013.main(GoRobot_m5d25y2013.java:181)
Java Result: 1
BUILD SUCCESSFUL (total time: 2 seconds)
最佳答案
根据您的编辑,问题是您在类定义中调用 stringList.add("Item");
。类字段中方法的执行应该在方法内部完成。在您的情况下,看起来这一行应该位于您的类构造函数内:
class Group { // Each Group is composed of positions
//fields definitions (and probably initialization of fields)...
//field declaration
ArrayList<String> stringList = new ArrayList<String>();
//this code can't be here
//stringList.add("Item");
Group() {
//move it here
stringList.add("Item");
//...
}
//rest of code...
}
关于java - Java 中出现错误 "package X does not exist",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16827143/
我的应用程序从一个有 5 个选项卡的选项卡栏 Controller 开始。一开始,第一个出现了它的名字,但其他四个没有名字,直到我点击它们。然后根据用户使用的语言显示名称。如何在选项卡栏出现之前设置选
我有嵌套数组 json 对象(第 1 层、第 2 层和第 3 层)。我的问题是数据表没有出现。任何相关的 CDN 均已导入。该表仅显示部分。我引用了很多网站,但都没有解决我的问题。 之前我使用标准表来
我正在尝试设置要显示的 Parse PFLoginViewController。这是我的一个 View Controller 的类。 import UIKit import Parse import
我遇到了这个问题,我绘制的对象没有出现在 GUI 中。我知道它正在被处理,因为数据被推送到日志文件。但是,图形没有出现。 这是我的一些代码: public static void main(Strin
我有一个树状图,其中包含出现这样的词...... TreeMap occurrence = new TreeMap (); 字符串 = 单词 整数 = 出现次数。 我如何获得最大出现次数 - 整数,
因此,我提示用户输入变量。如果变量小于 0 且大于 10。如果用户输入 10,我想要求用户再次输入数字。我问时间的时候输入4,它说你输入错误。但在第二次尝试时效果很好。例如:如果我输入 25,它会打印
我已经用 css overflow 属性做了一个例子。在这个例子中我遇到了一个溢出滚动的问题。滚动条出现了,但没有工作意味着每当将光标移动到滚动条时,在这个滚动条不活动的时间。我对此一无所知,所以请帮
我现在正在做一个元素。当您单击一个元素时,会出现以下信息,我想知道如何在您单击下一个元素而不重新单击同一元素时使其消失....例如,我的元素中有披萨,我想单击肉披萨看到浇头然后点击奶酪披萨看到浇头和肉
我有一个路由器模块,它将主题与正则表达式进行比较,并将出现的事件与一致的键掩码链接起来。 (它是一个简单的 url 路由过滤,如 symfony http://symfony.com/doc/curr
这个问题在这里已经有了答案: 9年前关闭。 Possible Duplicate: mysql_fetch_array() expects parameter 1 to be resource, bo
我在底部有一个带有工具栏的 View ,我正在使用 NavigationLink 导航到该 View 。但是当 View 出现时,工具栏显示得有点太低了。大约半秒钟后,它突然跳到位。它只会在应用程序启
我试图在我的应用程序上为背景音乐添加一个 AVAudioPlayer,我正在主屏幕上启动播放器,尝试在应用程序打开时开始播放但出现意外行为... 它播放并立即不断创建新玩家并播放这些玩家,因此同时播放
这是获取一个数字,获取其阶乘并将其加倍,但是由于基本情况,如果您输入 0,它会给出 2 作为答案,因此为了绕过它,我使用了 if 语句,但收到错误输入“if”时解析错误。如果你们能提供帮助,我真的很感
暂停期间抛出异常 android.os.DeadObjectException 在 android.os.BinderProxy.transactNative( native 方法) 在 androi
我已经为猜词游戏编写了一些代码。它从用户输入中读取字符并在单词中搜索该字符;根据字符是否在单词中,程序返回并控制一些变量。 代码如下: import java.util.Random; import
我是自动化领域的新手。这是我的简单 TestNG 登录代码,当我以 TestNG 身份运行该代码时,它会出现 java.lang.NullPointerException,双击它会突出显示我导航到 U
我是c#程序员,我习惯了c#的封装语法和其他东西。但是现在,由于某些原因,我应该用java写一些东西,我现在正在练习java一天!我要创建一个为我自己创建一个虚拟项目,以便让自己更熟悉 Java 的
我正在使用 Intellij,我的源类是 main.com.coding,我的资源文件是 main.com.testing。我将 spring.xml 文件放入资源文件中。 我的测试类位于 test.
我想要我的tests folder separate到我的应用程序代码。我的项目结构是这样的 myproject/ myproject/ myproject.py moduleon
这个问题已经有答案了: What is a NullPointerException, and how do I fix it? (12 个回答) 已关闭 6 年前。 因此,我尝试比较 2 个值,一个
我是一名优秀的程序员,十分优秀!