Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/apache-flex/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用求和表达式时出现空指针异常_Java_Spring_Hibernate_Jpa - Fatal编程技术网

Java 使用求和表达式时出现空指针异常

Java 使用求和表达式时出现空指针异常,java,spring,hibernate,jpa,Java,Spring,Hibernate,Jpa,在使用SpringMVC、JPA/Hibernate开发ERP时,我需要对实体运算的cr字段求和,但在使用createquery执行查询时需要求和 我试图对我正在构建的MVC ERP中实体操作的CR字段求和,但在使用createQuery执行查询时,我得到一个空指针异常 我在没有总和聚合的情况下测试了selectQuery,它运行得很好。我需要澄清 com.ensi.erp.dao.operationmanagerpl.sommescomputes `public float sommeComp

在使用SpringMVC、JPA/Hibernate开发ERP时,我需要对实体运算的cr字段求和,但在使用createquery执行查询时需要求和

我试图对我正在构建的MVC ERP中实体操作的CR字段求和,但在使用createQuery执行查询时,我得到一个空指针异常

我在没有总和聚合的情况下测试了selectQuery,它运行得很好。我需要澄清

com.ensi.erp.dao.operationmanagerpl.sommescomputes

`public float sommeComptes(int... doubles) {
        String liste= new String();
        String x;
        for (int d : doubles) {
            x=Integer.toString(d);
            x=x.concat(",");
            liste=liste.concat(x);
        }
    liste=liste.substring(0, liste.length()-1);
    String cc =" select sum(op.cr) from opération op ";
     System.out.println(cc);
        Query req= em.createQuery(cc);
        Number somme=(Number)req.getSingleResult();
        return somme.floatValue();  
    }
    `
com.ensi.entitis.operation

`@Entity
@Table(name="opérations")
public class opération implements Serializable {
@Id 
@Column(name="id")
    private int idop;
@Column(name="journal")
    private char journal;
@Column(name="compte")
    private int compte;
@Column(name="libellé")
    private String libellé;
@Column(name="dateop")
    private Date dateop;
@Column(name="dr")
    private float dr;
@Column(name="cr")
    private float cr;

//getters
public int getIdop(){return idop;}
public char getJournal(){return journal;}
public int getCompte(){return compte;}
public String getLibellé(){return libellé;}
public Date getDateop(){return  dateop;}
public float getDr(){return dr;}
public float getCr(){return cr;}

//setters
public  opération(){};
public  opération(int id,char j,int com,String lib, Date da ,float drr,float crr){idop=id;journal=j;compte=com;libellé=lib;dateop=da;dr=drr;cr=crr;};
public void setIdop(int op){idop=op;}
public void setJournal(char op){journal=op;}
public void setCompte(int op){compte=op;}
public void setLibellé(String op){libellé=op;}
public void setDateop(Date op){dateop=op;}
public void setDr(float op){ dr=op;}
public void setCr(float op){ cr=op;}


}`
com.ensi.metier.construireBilanImpl

package com.ensi.erp.metier;

import org.springframework.transaction.annotation.Transactional;

import com.ensi.erp.dao.OperationManager;
@Transactional
public class construireBilanImpl implements construireBilan {

    private  OperationManager opmanimpl2 ;

    private float immobilisations_corporelles=sommeComptes(1266,1322);
    private float immobilisation_corporelles;
    private float immobilisations_financieres;
    private float actifs_immobilisés;
    private float autres_actifs_nc;
    private float stocks;
    private float clients_et_comptes_rattachés;
    private float autres_actifs_courants;
    private float placements_et_autres;
    private float liquidités_et_equivalents;
    private float Total_actifs_courants;

    private float Capitaux_propres;
    private float Capital_social;
    private float Réserves;
    private float Autres_capitaux_propres;
    private float Résultat_Reporté;
    private float Total_avant_résultat;
    private float résultat_exercice;
    private float Total_capitaux_propres;


    private float Emprunts;
    private float Autres_passifs_financiers;
    private float Provisions;
    private float Total_passifs_nc;

    private float Fournisseurs_et_comptes_rattachés;
    private float Autres_passifs_courants;
    private float Concours_bancaires_et_autres;
    private float passifs_financiers;


    public construireBilanImpl(){};
    public void setOpmanimpl2(OperationManager x){opmanimpl2=x;}

    public float sommeComptes(int... doubles){
        return opmanimpl2.sommeComptes(doubles);


    }

    public float getImmobilisations_corporelles(){return immobilisations_corporelles;}
    public void setImmobilisations_corporelles(float x){immobilisations_corporelles=x;}
}
stackTrace

 INFO : org.springframework.web.context.ContextLoader - Root WebApplicationContext: initialization started
INFO : org.springframework.web.context.support.XmlWebApplicationContext - Refreshing Root WebApplicationContext: startup date [Sun Jun 22 20:55:39 CEST 2014]; root of context hierarchy
INFO : org.springframework.beans.factory.xml.XmlBeanDefinitionReader - Loading XML bean definitions from URL [file:/C:/Users/housseminfo/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/ERP_PCD/WEB-INF/classes/root-context.xml]
INFO : org.springframework.context.annotation.ClassPathBeanDefinitionScanner - JSR-250 'javax.annotation.ManagedBean' found and supported for component scanning
INFO : org.springframework.context.annotation.ClassPathBeanDefinitionScanner - JSR-330 'javax.inject.Named' annotation found and supported for component scanning
INFO : org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor - JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
INFO : org.springframework.beans.factory.support.DefaultListableBeanFactory - Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@1888c363: defining beans [datasource,persistenceUnitManager,entityManagerFactory,transactionManager,operationmanager,opser,operationmanager2,bilan,org.springframework.aop.config.internalAutoProxyCreator,org.springframework.transaction.annotation.AnnotationTransactionAttributeSource#0,org.springframework.transaction.interceptor.TransactionInterceptor#0,org.springframework.transaction.config.internalTransactionAdvisor,operationController,homeController,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.internalPersistenceAnnotationProcessor,org.springframework.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor]; root of factory hierarchy
INFO : org.springframework.beans.factory.support.DefaultListableBeanFactory - Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@1888c363: defining beans [datasource,persistenceUnitManager,entityManagerFactory,transactionManager,operationmanager,opser,operationmanager2,bilan,org.springframework.aop.config.internalAutoProxyCreator,org.springframework.transaction.annotation.AnnotationTransactionAttributeSource#0,org.springframework.transaction.interceptor.TransactionInterceptor#0,org.springframework.transaction.config.internalTransactionAdvisor,operationController,homeController,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.internalPersistenceAnnotationProcessor,org.springframework.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor]; root of factory hierarchy
ERROR: org.springframework.web.context.ContextLoader - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'bilan' defined in URL [file:/C:/Users/housseminfo/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/ERP_PCD/WEB-INF/classes/root-context.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.ensi.erp.metier.construireBilanImpl]: Constructor threw exception; nested exception is java.lang.NullPointerException
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1011)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:957)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:490)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:607)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
    at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:383)
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:283)
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4961)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5455)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
    at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
    at java.util.concurrent.FutureTask.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.ensi.erp.metier.construireBilanImpl]: Constructor threw exception; nested exception is java.lang.NullPointerException
    at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:163)
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:87)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1004)
    ... 23 more
Caused by: java.lang.NullPointerException
    at com.ensi.erp.metier.construireBilanImpl.sommeComptes(construireBilanImpl.java:48)
    at com.ensi.erp.metier.construireBilanImpl.<init>(construireBilanImpl.java:11)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:148)
    ... 25 more
juin 22, 2014 8:55:40 PM org.apache.catalina.core.StandardContext listenerStart
Grave: Exception lors de l'envoi de l'évènement contexte initialisé (context initialized) à l'instance de classe d'écoute (listener) org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'bilan' defined in URL [file:/C:/Users/housseminfo/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/ERP_PCD/WEB-INF/classes/root-context.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.ensi.erp.metier.construireBilanImpl]: Constructor threw exception; nested exception is java.lang.NullPointerException
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1011)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:957)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:490)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:607)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
    at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:383)
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:283)
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4961)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5455)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
    at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
    at java.util.concurrent.FutureTask.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.ensi.erp.metier.construireBilanImpl]: Constructor threw exception; nested exception is java.lang.NullPointerException
    at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:163)
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:87)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1004)
    ... 23 more
Caused by: java.lang.NullPointerException
    at com.ensi.erp.metier.construireBilanImpl.sommeComptes(construireBilanImpl.java:48)
    at com.ensi.erp.metier.construireBilanImpl.<init>(construireBilanImpl.java:11)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:148)
    ... 25 more
INFO:org.springframework.web.context.ContextLoader-根WebApplicationContext:初始化已开始
信息:org.springframework.web.context.support.XmlWebApplicationContext-刷新根WebApplicationContext:启动日期[Sun Jun 22 20:55:39 CEST 2014];上下文层次结构的根
信息:org.springframework.beans.factory.xml.XmlBeanDefinitionReader-从URL[文件:/C:/Users/housseminfo/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/ERP_PCD/WEB-INF/classes/root context.xml]加载xml bean定义
信息:org.springframework.context.annotation.ClassPathBeanDefinitionScanner-JSR-250“javax.annotation.ManagedBean”找到并支持组件扫描
信息:org.springframework.context.annotation.ClassPathBeanDefinitionScanner-JSR-330“javax.inject.Named”找到并支持用于组件扫描的注释
信息:org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor-JSR-330“javax.inject.inject”注释已找到并支持自动布线
信息:org.springframework.beans.factory.support.DefaultListableBeanFactory-在org.springframework.beans.factory.support中预实例化单例。DefaultListableBeanFactory@1888c363:定义bean[datasource,persistenceUnitManager,EntityManager工厂,transactionManager,operationmanager,opser,operationmanager2,bilan,org.springframework.aop.config.internalAutoProxyCreator,org.springframework.transaction.annotation.AnnotationationTransactionAttributeSource#0,org.springframework.transaction.interceptor.TransactionInteractionInterceptor#0,org.springframework。transaction.config.internalTransactionAdvisor,operationController,homeController,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation、 internalCommonAnnotationProcessor,org.springframework.context.annotation.internalPersistenceAnnotationProcessor,org.springframework.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor];工厂层次结构的根
信息:org.springframework.beans.factory.support.DefaultListableBeanFactory-销毁org.springframework.beans.factory.support中的单例。DefaultListableBeanFactory@1888c363:定义bean[datasource,persistenceUnitManager,EntityManager工厂,transactionManager,operationmanager,opser,operationmanager2,bilan,org.springframework.aop.config.internalAutoProxyCreator,org.springframework.transaction.annotation.AnnotationationTransactionAttributeSource#0,org.springframework.transaction.interceptor.TransactionInteractionInterceptor#0,org.springframework。transaction.config.internalTransactionAdvisor,operationController,homeController,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation、 internalCommonAnnotationProcessor,org.springframework.context.annotation.internalPersistenceAnnotationProcessor,org.springframework.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor];工厂层次结构的根
错误:org.springframework.web.context.ContextLoader-上下文初始化失败
org.springframework.beans.factory.BeanCreationException:创建URL[文件:/C:/Users/housseminfo/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/ERP_PCD/WEB-INF/classes/root context.xml]中定义的名为“bilan”的bean时出错:bean实例化失败;嵌套异常为org.springframework.beans.beaninstanicationException:无法实例化bean类[com.ensi.erp.metier.construireBilanImpl]:构造函数引发异常;嵌套异常为java.lang.NullPointerException
位于org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.InstanceBean(AbstractAutowireCapableBeanFactory.java:1011)
位于org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:957)
位于org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:490)
位于org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461)
位于org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
位于org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
位于org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
位于org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
位于org.springframework.beans.factory.support.DefaultListableBeanFactory.PreInstanceSingleton(DefaultListableBeanFactory.java:607)
位于org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
位于org.springframework.context.support.AbstractApplicationContext.refresh(Abstra
java.lang.NullPointerException
at com.ensi.erp.metier.construireBilanImpl.sommeComptes(construireBilanImpl.java:48)
at com.ensi.erp.metier.construireBilanImpl.<init>(construireBilanImpl.java:11)
private  OperationManager opmanimpl2 ;
// so opmanimpl2 is null.

private float immobilisations_corporelles = sommeComptes(1266,1322)

public float sommeComptes(int... doubles){
    return opmanimpl2.sommeComptes(doubles);
    //       ^-- what's the value of opmanimpl2 again?
}