JAVA
我的游戏中有一个ArrayList来存储游戏中的所有粒子.我有一个访问ArrayList来更新物理的更新方法,我有一个访问ArrayList的渲染方法来渲染屏幕上的粒子,还有一个MouseClick侦听器,当它检测到MouseClick时,它会向ArrayList添加一个新粒子.
我的问题是我不断收到java.util.ConcurrentModificationException.这是因为当我同时点击它渲染时,两个方法都试图访问ArrayList.是否有同时访问ArrayList的解决方案(不同的数据类型?).
一些代码可以帮助 -
ArrayList声明
ArrayList<Particle> ParticleList = new ArrayList<Particle>();
Run Code Online (Sandbox Code Playgroud)
粒子类定义
public class Particle {
int x;
int y;
Color colour;
int type;
//0:wall
public Particle(int x,int y,Color colour,int type)
{
this.x = x;
this.y = y;
this.colour = colour;
this.type = type;
}`
Run Code Online (Sandbox Code Playgroud)
渲染方法
for(Particle e : this.ParticleList)
{
g.fillRect(e.x, e.y, 1, 1);
}
Run Code Online (Sandbox Code Playgroud) 我尝试在 Android 中使用 NumberFormatter 格式化数字。我使用下面的代码,它完美地工作:
NumberFormat formatter = new DecimalFormat("###,###");
String myFormattedString = formatter.format(123456);
Run Code Online (Sandbox Code Playgroud)
但是,当我使用带有空格的模式时,就像这样:new DecimalFormat("###,# ##");它会抛出一个IllegalArgumentException. 我已经阅读了有关 NumberFormatter 和 DecimalFormatter 的文档,但没有发现有关模式中空格的信息。谁能解释我为什么不能使用空格或如何将它们添加为允许的字符。提前致谢!!!
我有一个HashMap,我需要按键排序.我必须做什么?如果你能给我一些例子,我会很高兴.无论如何,谢谢你.
我已经使用glassfish作为我的服务器创建了一个带有neatbeans的球衣网络服务,一切正常但我在尝试在websphere 7上安装相同的应用程序时遇到问题.
我收到此错误"错误500处理请求时出错:/ibm/console/upload.do消息:java.lang.NoClassDefFoundError:javax.servlet.ServletInputStream".
我甚至尝试创建一个简单的Web应用程序,并尝试在websphere上部署,再次,我有同样的错误.
有想法的人吗?我非常需要你的帮助.提前致谢
是否Collections.syncronizedList(new ArrayList())能有效地使ArrayList的载体?如果没有那么它还有什么额外的作用?如果是,那么为什么它首先被引入?
谢谢.
我有一个课程,我想将其注释为服务.我做的是:
@Service
public class PaymentInTermsServiceImpl implements PaymentInTermsService {
@Override
public SOAPMessage createSOAPMessage(String clientNumber, OrderData order, String accUrl, String refUrl, String rejUrl) throws SOAPException
{
Run Code Online (Sandbox Code Playgroud)
现在Eclipse给出了一个错误说:"无法将表单服务转换为注释"我在我的frontend-servlet.xml中有这个
<!-- Scan for annotation configured controller -->
<context:component-scan base-package="frontend.web.*"/>
Run Code Online (Sandbox Code Playgroud) 我在通过RMI传输的对象上遇到一个奇怪的问题.这已经破坏了我的头几天了,我想知道是否有人可以帮助解决这个问题.
我有一个Garage类(也是一个JPA实体,如果它是相关的)我推送到一个名为X over RMI的java进程(所以这个对象被序列化).Garage对象存储一个名为Car(也是JPA实体)的对象列表,这些对象也是Serializable.
Garage上的equals方法基本上是在汽车列表中调用equals(一个ArrayList)
当我在java进程中调用equals时,它不会因为某种原因在列表上调用equals,就像我期望它在列表中的所有Cars上调用equals来检查列表是否相等而不执行此操作.
奇怪的是,当单元测试时,它确实调用了Cars ArrayList的所有成员的equals.我甚至将对象序列化为单元测试的一部分,这也有效.有任何想法吗?我希望我能解决问题,随时请求任何信息澄清任何事情.
编辑:我几乎可以肯定它的ArrayList很奇怪,因为当我在我的对象中手动执行equals而不是在汽车列表中调用equals时我在汽车列表上执行了foreach循环并在每辆Car上调用equals(就像我预期的ArrayList equals无论如何,它按预期工作)
@Entity
@Table(schema="pdw", name="garage")
public class Garage
implements Comparable<Garage> ,
Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private String id;
private String name;
@OneToMany(cascade = CascadeType.ALL)
@JoinTable(schema="pdw")
private List<Car> cars = new ArrayList<Car>();
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name; …Run Code Online (Sandbox Code Playgroud) 如何在Eclipse中配置我的Web应用程序(基于Servlet并部署到Tomcat)以使用Spring框架.我只需要IoC容器(仅限Bean和ApplicationContext),而不是Spring MVC.如何为此配置web.xml?
问候
import java.util.*;
public Class C
{
final Vector v;
C()
{
v=new Vector();
}
C(int i)
{
//Here, it is an error. v might not have been initialized.
}
public void someMethod()
{
System.out.println(v.isEmpty());
}
public static void main(String[] args)
{
C c=new C();
c.someMethod();
}
}
Run Code Online (Sandbox Code Playgroud)
上面的代码是编译时错误.我知道,但它说(在NetBeans中)变量v应该被初始化.当我在重载的构造函数中初始化它时,它修复了问题并打印"true".我的问题是为什么我应该在重载版本的构造函数中再次初始化它.(我在默认构造函数中初始化了一次)并且我甚至没有使用重载版本.为什么?
java ×10
collections ×3
spring ×3
android ×2
arraylist ×2
servlets ×2
arrays ×1
concurrency ×1
eclipse ×1
jersey ×1
jpa ×1
rmi ×1
service ×1
spring-aop ×1
tomcat ×1
websphere ×1
websphere-7 ×1