gpt4 book ai didi

java - 在游戏中传递数组

转载 作者:太空宇宙 更新时间:2023-11-04 15:23:45 27 4
gpt4 key购买 nike

我在设置 boolean 值数组时遇到了一些问题。我在模型中定义了数组:

   @Entity
public class Ssr extends Model{

@Id
public int num;
public boolean[] row1;

在我的 View 文件中,我正在创建表格

...

<td>Network</td>
@for(a <- 1 to 10){
<td>
@checkbox(ssrForm("row1[@a]"),'_label->None)
</td>
}

...

当我尝试将此值传递到下一个屏幕时,值不会保存在 ssr 对象中并且 axception 显示:

[info] play - database [default] connected at jdbc:h2:mem:play
[error] c.a.e.s.t.r.ImmutableMetaFactory - Was unable to use reflection to find
a constructor and appropriate getters forimmutable type class [Z. The errors wh
ile looking for the getter methods follow:
[error] c.a.e.s.d.p.DeployCreateProperties - Error with models.Ssr field:row1
java.lang.RuntimeException: Unable to use reflection to build ImmutableMeta for
class [Z. Associated Errors trying to find a constructor and getter methods hav
e been logged
at com.avaje.ebeaninternal.server.type.reflect.ImmutableMetaFactory.crea
teImmutableMeta(ImmutableMetaFactory.java:53) ~[avaje-ebeanorm.jar:na]
at com.avaje.ebeaninternal.server.type.DefaultTypeManager.recursiveCreat
eScalarTypes(DefaultTypeManager.java:205) ~[avaje-ebeanorm.jar:na]
at com.avaje.ebeaninternal.server.deploy.parse.DeployCreateProperties.cr
eateProp(DeployCreateProperties.java:321) [avaje-ebeanorm.jar:na]
at com.avaje.ebeaninternal.server.deploy.parse.DeployCreateProperties.cr
eateProp(DeployCreateProperties.java:341) [avaje-ebeanorm.jar:na]
at com.avaje.ebeaninternal.server.deploy.parse.DeployCreateProperties.cr
eateProperties(DeployCreateProperties.java:128) [avaje-ebeanorm.jar:na]
at com.avaje.ebeaninternal.server.deploy.parse.DeployCreateProperties.cr
eateProperties(DeployCreateProperties.java:54) [avaje-ebeanorm.jar:na]

我应该使用列表而不是数组吗?

感谢您的帮助。

最佳答案

我找到了解决方案。如果您不需要将数组存储在数据库中,只需在变量声明中添加“transient”关键字即可。

@Entity
public class Ssr extends Model{

@Id
public int num;
public transient boolean[] row1;

关于java - 在游戏中传递数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20094092/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com