Tag: illegalargumentexception

将GregorianCalendar与SimpleDateFormat一起使用

因此,我一直在思考这个(应该是)简单的练习,让程序将日期字符串转换为GregorianCalendar对象,格式化它,并在完成时将其作为字符串再次返回。 这是一个程序的最后一点,它从文件中获取文本,将其分解为单个记录,然后将记录分成单独的数据并将它们分配给一个人对象。 我已经在多个地方检查了代码,代码完全按照它应该执行的操作,直到我调用格式函数,这会抛出IllegalArgumentException。 GergorianCalendar对象被赋予它应该被分配的值(虽然打印它是另一个故事,如下所示……),但格式不接受格式化的对象。 不幸的是,导师不太确定如何使用GregorianCalendar和SimpleDateFormat(但指派我们使用它们)并且说“Just Google it”……我试过,我发现没有任何帮助。 我到目前为止的代码是: public class DateUtil { public static GregorianCalendar convertFromDMY(String dd_mm_yy) throws ParseException{ // this actually works, got rid of the original code idea String[] splitDate = dd_mm_yy.split(“-“); int days = Integer.parseInt(splitDate[0]); int month = Integer.parseInt(splitDate[1]); int year = Integer.parseInt(splitDate[2]); // dates are going in right, checked in print […]

问题格式化JTable中的字段 – Integer和Double之间的差异

更新 当columnClass为Double时,确认为JTable上的错误无法将给定的对象格式化为数字(错误ID:7051636) 。 您可以随意投票,或者如果您有替代(更好)的解决方案,请将其作为对报告的评论发布。 我正在构建一个JTable,其中包含一个扩展AbstractTableModel的自定义表模型。 我的模型需要支持空行显示和排序。 所以我接受了这篇文章来实现它,现在工作得非常好。 我仍然遇到JTable格式化字段的问题。 假设我有以下型号: public class MyModel extends AbstractTableModel{ public Object[] types= {new Integer(0), “”}; public static final Object EMPTY_ROW = “”; @Override public Object getValueAt(int rowIndex, int columnIndex) { return this.EMPTY_ROW; } public Class getColumnClass(int c) { if (c > this.types.length – 1) return null; else return this.types[c].getClass(); } […]