- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这可能是一个非常菜鸟的问题,但我想我会在这里碰碰运气。
所以基本上我必须做一个分配,它是这样的:
我必须创建一个构造函数,但变量“naam”不能为 null 或为空 (“”),变量“geboortedatum”不能是 future 的日期,也不能是与今天相同的日期和最后一个变量“boeken”与变量“naam”具有相同的要求(因为它不能为 null 也不能为“”)。
这就是我的构造器的样子,我只能编辑这部分,因为另一部分是我们老师给的,不能编辑。
if (this.naam == null || this.naam.equals("")) {
throw new IllegalArgumentException("Fill in name");
} else {
this.naam = naam;
}
Date vandaag = new Date();
if (this.geboorteDatum >= vandaag.getTime()) {
throw new IllegalArgumentException("Date must be in the past");
} else {
this.geboorteDatum = geboortedatum;
}
if (this.boeken == null || Arrays.toString(boeken).equals("")) {
throw new IllegalArgumentException("Can't be empty");
} else {
this.boeken = boeken;
}
它一直抛出我的第一个异常,我不明白为什么。这可能是一个非常愚蠢的问题,但我似乎无法找出原因。
任何帮助将不胜感激,提前致谢
最佳答案
您正在测试 this.naam
,它是该类的实例数据成员。如果正如您所说,这是在构造函数中,那么除非您有初始化程序,否则它可能是 null
。
您可能打算测试 naam
,构造函数的参数:
if (naam == null || naam.equals("")) {
// ^---------------^------------------ no `this.` here
throw new IllegalArgumentException("Fill in name");
} else {
this.naam = naam;
}
对于 geboortedatum
和 boeken
也是如此。
关于java - 即使不满足条件也一直抛出异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20997248/
我有一个在 Android 市场上相当流行的应用程序,它允许数以万计的用户按下一个按钮并向它发出语音命令。然后我就可以做很多不同的事情,比如给他们提供当前的天气预报等等...... 无论如何,我的应用
令人惊讶的是,标题基本上解释了它。我们有一个我们的客户制作的页面,我们正在重新创建该页面。 页面高度会一直增加,直到(我假设是这样)浏览器达到它的极限。我已经尝试过 Firebug 和 W3 验证器,
我是 react-native 的新手,试图创建我自己的组件,但它一直显示一个空屏幕。 这是我的组件代码 class BoxComponent extends Component { cons
我正在为我的 PHP 元素创建一个非常简单的博客,但遇到了一个简单的问题。我无法让我的页眉图像一直 float 。我有一个横幅,左边有一些文字,我有一个 1px 的切片,在可以选择的任何分辨率的宽度上
为什么我可以在另一个 Controller 的 View 中访问一个 Controller 的辅助方法?有没有办法在不破解/修补 Rails 的情况下禁用它? 最佳答案 @George Schreib
我正在使用带有最新 ADT 插件的 Eclipse Kepler SP2。每隔一分钟 Eclipse 就会说“为 Android 4.4.2 加载数据”并阻止我想做的一切。我在不同的文件夹中有几个 E
我是一名优秀的程序员,十分优秀!