简体   繁体   English

无法使用Slick2d和Java使用列表

[英]Can't get lists working using Slick2d and Java

Could anyone help me with why I'm unable to add to either of the lists created? 有人可以帮助我为什么我无法添加到创建的两个列表中吗? The second list is only created to illustrate the problem. 创建第二个列表只是为了说明问题。 Thanks for any help! 谢谢你的帮助!

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");
}

If the code you posted is accurate, you need to have the method calls placed in a method or the constructor. 如果您发布的代码正确,则需要将方法调用放置在方法或构造函数中。 You can initialize variables outside of methods, but that's it. 您可以在方法之外初始化变量,仅此而已。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM