【问题标题】:Can't get lists working using Slick2d and Java无法使用 Slick2d 和 Java 获取列表
【发布时间】:2014-06-02 17:36:55
【问题描述】:

谁能帮我解释为什么我无法添加到任何一个创建的列表中?创建第二个列表只是为了说明问题。谢谢你的帮助!

import java.util.ArrayList;
import java.util.List;

import org.newdawn.slick.Image;


public class Snake {
    private Image head = new Image("data/head.png");
    private static Image body = new Image("data/body.png");

    ArrayList<Point> snakeCoords = new ArrayList<Point>(3);

    Point headCoord = new Point(300, 300);
    Point firstBody = new Point(300, 325);
    Point secondBody = new Point(300, 350);

    snakeCoords.add(headCoord);

    List<String> list = new ArrayList<String>();
    list.add("Does this work");
}

【问题讨论】:

  • 只是为了确保您添加到方法或构造函数列表中的行?
  • 也许你可以把函数调用放在一个方法中。
  • 哈哈,天哪,非常感谢你们!

标签: java slick2d


【解决方案1】:

如果您发布的代码是准确的,您需要将方法调用放在方法或构造函数中。您可以在方法之外初始化变量,仅此而已。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-14
    • 1970-01-01
    • 2015-12-21
    • 2016-12-05
    相关资源
    最近更新 更多