Org.hibernate.util.ReflectHelper.getConstructor NULL pointer exception

Source: Internet
Author: User
Tags list of attributes

First write to you my solution, the benefit of the hand Party:

Most of the problem is in the construction, you must have written it.

Select New (xxx,xxx,xxx) from XXX ...

1. Check if your construction does not match the type and the actual type

2.java.util.date This class is more personal.

3. Keep your construction parameter name and the class member variable name the same.

I solved it with 3, you can try, although I have not found the basis.

Focus on 2 and 3.

Suppose we have a construct:

Public XXX (String a,date b,bigdecimal Cc) {  this.a = A;  this.b = b;  This. CC = CC;}

And you have such a list of attributes:

Private String a;private Date b;private BigDecimal Cc;


This basically contains the errors you may have encountered.

On the 2nd, you can't write the date B directly in your structure.

Public XXX (String a,string b,bigdecimal Cc) {  this.a = A;  this.b = datehelper.parsestring (inserttime,null);  This. CC = CC;}
public static Date parsestring (String s,string format) throws Parseexception{<span style= "White-space:pre" ></ Span>if (format==null) format = "Yyyy-mm-dd HH:mm:ss"; <span style= "White-space:pre" ></span> SimpleDateFormat df = new SimpleDateFormat (format); <span style= "White-space:pre" ></span>return Df.parse (s);}
You can read it, can't you read Google?

About the 3rd, if you write a

Public XXX (String a,string b,bigdecimal cc) {  this.a = A;  this.b = datehelper.parsestring (inserttime,null);  This. CC = CC;}

You think it's the same, don't you? But I can't. Must be the same as the property name.

I found the part that throws the exception:

public static Constructor More ... getconstructor (class Clazz, type[] types) throws propertynotfoundexception {336final constructor[] candidates = clazz.getconstructors () 337for (int i = 0; i < candidat Es.length;  i++) {338final Constructor Constructor = candidates[i];339final class[] params = Constructor.getparametertypes (); 340if ( Params.length = = types.length) {341boolean found = true;342for (int j = 0; J < Params.length; J + +) {343final Boolea n OK = params[j].isassignablefrom (Types[j].getreturnedclass ()) | | (344types[j] instanceof primitivetype &&345params[j] = = ((primitivetype) types[j]). Getprimitiveclass () 346); 347if (!ok) {348found = False;349break;350}351}352if (found) {353if (!ispublic (Clazz, constructor)) {354constructo R.setaccessible (true); 355}356return constructor;357}358}359}360throw new Propertynotfoundexception ("no appropriate Constructor in class: "+ Clazz.getname ()); 361} 
Take a look at line 343, there is a ' isassignablefrom ' method.

Determines if the class or interface represented by this class object was either the same as, or is a superclass or Superin Terface of, the class or interface represented by the specified class parameter. It returns True if so; Otherwise it returns false. If this class object represents a primitive type, this method returns True if the specified Class parameter is exactly thi S Class object; Otherwise it returns false.  Specifically, this method tests whether the type represented by the specified Class parameter can is converted to the type Represented by this Class object via an identity conversion or via a widening reference conversion. See the Java Language specification, sections 5.1.1 and 5.1.4, for details. Parameters:cls the Class object to being Checkedreturns:the Boolean value indicating whether objects of the type CLS can be a Ssigned to objects of this classthrows:nullpointerexception if the specified Class parameter is null. since:jdk1.1439 Native Boolean more ... IsassIgnablefrom (class<?> CLS); 
I have no proof that it is not from this, the stack information actually does not print it, only the exception that is printed to the ' GetConstructor ' method 343 line.

So, if you have the time and interest to find out why, please reply me.



Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Org.hibernate.util.ReflectHelper.getConstructor NULL pointer exception

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.