Org. apache. commons. beanutils. ConversionException: No value specified Solution

Source: Internet
Author: User

When non-built-in objects such as java. SQL. Date are used, this exception occurs if the object is null. The simplest method is to ensure that non-built-in objects are not null.

As the demand changes in the project business, there is no guarantee that the built-in objects are not null. Therefore, it is necessary to solve this exception to achieve a general effect. The following is a solution to this exception:

/** Time to market */
Private java. SQL. Date timeToMarket;
// If timeToMarket is null, The org. apache. commons. beanutils. ConversionException: No value specified exception is thrown.
// Public Date getTimeToMarket (){
// Return timeToMarket;
//}
//
// Public void setTimeToMarket (Date timeToMarket ){
// This. timeToMarket = timeToMarket;
//}


// Solution
Public String getTimeToMarket (){
If (timeToMarket = null) return null;
DateFormat dateFormat = DateFormat. getDateInstance ();
Return dateFormat. format (this. timeToMarket );
}

Public void setTimeToMarket (String timeToMarket ){
If (timeToMarket = null | "". equals (timeToMarket. trim ())){
This. timeToMarket = null;
} Else {
Try {
DateFormat dateFormat = DateFormat. getDateInstance ();
This. timeToMarket = new java. SQL. Date (dateFormat. parse (
TimeToMarket). getTime ());
} Catch (ParseException e ){
E. printStackTrace ();
}
}
}

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.