Exception in thread "main" java.lang.IllegalArgumentException

1、错误描述

Exception in thread "main" java.lang.IllegalArgumentException: Cannot format given Object as a Date
	at java.text.DateFormat.format(DateFormat.java:301)
	at java.text.Format.format(Format.java:157)
	at com.you.util.DateBefore.getMonthBefore(DateBefore.java:24)
	at com.you.util.DateBefore.main(DateBefore.java:33)

2、错误原因

/**
 *
 */
package com.you.util;

import java.text.SimpleDateFormat;
import java.util.Calendar;

/**
 * @author YouHaidong
 *
 */
public class DateBefore
{
	/**
	 *
	 * @return
	 */
	public static String getMonthBefore(String subStr)
	{
		Calendar calendar = Calendar.getInstance();
		calendar.add(Calendar.MONTH, -12);
		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMM");
		subStr = sdf.format(calendar);
		return subStr;
	}

	/**
	 * @param args
	 */
	public static void main(String[] args)
	{
		String date = getMonthBefore("2014-02");
		System.out.println(date);
	}

}

3、解决办法

时间: 2024-11-11 09:09:16

Exception in thread "main" java.lang.IllegalArgumentException的相关文章

启动hive错误:Exception in thread "main" java.lang.IllegalArgumentException

启动hive错误:Exception in thread "main" java.lang.IllegalArgumentException 2018-03-20 15:19:07 Gethin_H 阅读数 1357更多 分类专栏: Hive 版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明. 本文链接:https://blog.csdn.net/Gethin_H/article/details/79626223 启动hive时报错了

【异常】Exception in thread "main" java.lang.IllegalArgumentException: Illegal pattern c

在windows上执行的时候,option(“timestampFormat”, “yyyy/MM/dd HH:mm:ss ZZ”)必须带上,不然报错: Exception in thread "main" java.lang.IllegalArgumentException: Illegal pattern component: XX. 使用比如:val df1 = spark.read.format("json").option("timestampF

Exception in thread "main" java.lang.IllegalArgumentException: java.net.URISyntaxException: Relative path in absolute URI: ${system:java.io.tmpdir%7D/$%7Bsystem:user.name%7D

问题原因是Hive里面配置的相对路径没有找到,我们可以直接在文件里面修改为绝对路径. 1.在hive下面窗口temp文件夹 cd /opt/hive mkdir temp cd temp 2.查看temp所在路径 pwd temp 3.进入hive-site.xml里面 vim /opt/hive/conf/hive-site.xml 4.搜索system:java.io.tmpdir字样的东西,修改为绝对路径(/opt/hive/apache-hive-2.3.6-bin/temp)就可以了.

Spring报错:Exception in thread "main" java.lang.IllegalArgumentException at org.springframework.asm.ClassReader.<init>(Unknown Source)

简单搭建了一个Spring Maven工程就报错: 看到网上说是JDK 7 和 Spring3.x :JDK编译级别设置成1.7,仍然没有得到解决,采用版本为  3.2.0.RELEASE <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId>

OGNL报错:Exception in thread &quot;main&quot; java.lang.ExceptionInInitializerError

使用OGNL进行简单的测试时,获取对象的属性,结果出现报错,信息如下: Exception in thread "main" java.lang.ExceptionInInitializerError at ognl.ASTProperty.getValueBody(ASTProperty.java:114) at ognl.SimpleNode.evaluateGetValueBody(SimpleNode.java:212) at ognl.SimpleNode.getValue(

Hbase delete遇到的常见异常: Exception in thread &quot;main&quot; java.lang.UnsupportedOperationException

hbase 执行批量删除时出现错误: Exception in thread "main" java.lang.UnsupportedOperationException at java.util.AbstractList.remove(AbstractList.java:161) at org.apache.hadoop.hbase.client.HTable.delete(HTable.java:852) 这种异常其实很常见,remove操作不支持,为什么会出现不支持的情况呢?检查

Exception in thread &quot;main&quot; java.lang.NoSuchMethodError: org.testng.TestNG.configure(Lorg/testng/CommandLineArgs;)V

TestNG运行时报以下错误: Exception in thread "main" java.lang.NoSuchMethodError: org.testng.TestNG.configure(Lorg/testng/CommandLineArgs;)V at org.testng.remote.AbstractRemoteTestNG.configure(AbstractRemoteTestNG.java:77) at org.testng.remote.RemoteTestN

Exception in thread &quot;main&quot; java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory

MyEclipse运行的时候报错,菜鸟不理解是什么意思,最后找了一些资料才知道是因为缺少commons-logging.jar包 Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory at org.apache.commons.httpclient.HttpClient.<clinit>(HttpClient.java:66) at c

Exception in thread &quot;main&quot; java.lang.NoClassDefFoundError: Demo (wrong name: com/zhangyun/Demo)解决办法

介绍一个Java初学者可能会遇到的问题 首先,创建一个类,如下: 文件名:Demo.java package com.zhangyun; public class Demo { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub System.out.println("Hello World!"); } } 然后我找到对应在磁盘的位置,如下: E