Exception in thread "main" java. lang. IllegalArgumentException, java. lang
1. Error description
Exception in thread "main" java.lang.IllegalArgumentException: Cannot format given Object as a Dateat 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. Error cause
/** * */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. Solution
About Exception in thread "main" javalangIllegalArgumentException
IllegalArgumentException ---------
Indicates the exception class when the parameter is passed to a method that is invalid or incorrect.
****************************************
Public JLabel (String text,
Int horizontalAlignment) create a JLabel instance with the specified text and horizontal alignment. The label is vertically centered and aligned in the display area.
Parameters:
Text-text displayed by tags.
HorizontalAlignment-one of the following constants defined in SwingConstants: LEFT, CENTER, RIGHT, LEADING, or TRAILING.
Therefore, this JLabel. NORTH is invalid.
Exception in thread "main" javalangIllegalArgumentException:
Run successfully. It indicates that your jdk installation environment is incorrect. How can I install jdk?
Decompress the jdk package and proceed to the next step.
Then configure the environment variable
Right-click my computer and choose Properties> advanced with Environment Variables
Under the user variable of Administrator
Click "new" and enter "=" variable name "classpath variable value" C: \ Program Files \ java \ jdk1.6.0 _ 10 "." OK"
Enter the JAVA_HOME variable value C: \ Program Files \ java \ jdk1.6.0 _ 10 after creating the file.
Find the PATH in the system variable to add; % JAVA_HOME % \ bin; OK
After the environment variable configuration is complete, Enter cmd in dos and enter java. If the configuration is correct, add C: \ Program Files \ Java \ jdk1.6.0 _ 07 to the jdk installation path for you.