我正在调用一个长的构造函数。然而,长字段被设置为 -1:
LogCat:“将包的 ID 设置为 -29270339915449391104。getID() 现在返回 -1”
我不知道为什么。如果你投入很长时间,那么不应该有任何转换问题吗?我错过了什么?
private long ID;
public AFileOrPackView(Context context, long ID) {
super(context);
this.ID = ID;
Log.d("asd", "set the pack's id to " + ID + ". getID() now returns " + this.getId());
}
public Long getID() {
return this.ID;
}
最佳答案
您的代码中有错别字。
this.getId()
应该是
this.getID()
此外,如果您不需要,而不是返回一个 Long
对象,您应该返回 long
原始类型。
改变:
public Long getID() {
return this.ID;
}
在
public long getID() {
return this.ID;
}
关于java/android - long 没有明显原因设置为 -1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14215618/