Exception in thread & quot; main & quot; java. lang. IllegalArgumentException, java. lang

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.