cancel
Showing results for 
Search instead for 
Did you mean: 

I Get Error NullPointerException When Use NodeService

geyson_santana
Champ in-the-making
Champ in-the-making
My code:

79            ServiceRegistry serviceRegistry = (ServiceRegistry) beanFactory.getBean(ServiceRegistry.SERVICE_REGISTRY);
80            NodeService nodeService = serviceRegistry.getNodeService();
81           
82            NodeRef nodeRef = new NodeRef("workspace://SpacesStore/" + IdNode);
83            System.out.println("Node: "+nodeRef.getId());
84            QName CUSTOM_ASPECT_QNAME = QName.createQName("custom.model", "tipo_documento");
85            nodeService.setProperty(nodeRef, CUSTOM_ASPECT_QNAME, propertyOne);

I get(in line 79):

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
   at Telas.SubMenuNovo.adicionaPropriedades(SubMenuNovo.java:79)

I want set up properties in a document with custom metadata with my application. The custom metadata just work at interface Alfresco Explorer. The line 83 prints ok the IDnode(Node of the document).  Anyone help me? Thanks!
2 REPLIES 2

yogeshpj
Star Contributor
Star Contributor
From the error it seems that either ServiceRegistry or beanFactory is coming with null value.

I solved my problem using the code:

public void adicionaPropriedades(String node, String value) throws RemoteException {
        try {
            Store spacesStore = new Store(Constants.WORKSPACE_STORE, "SpacesStore");
            //create the node reference
            Reference reference = new Reference(spacesStore, node, null);
            //create the predicate
            Predicate predicate = new Predicate();
            predicate.setNodes(new Reference[]{reference});
           
            QName PROP_QNAME_MY_PROPERTY_TIPO = QName.createQName("custom.model", "tipo_documento");
            QName PROP_QNAME_MY_PROPERTY_NUMERO = QName.createQName("custom.model", "numero");
           
            NamedValue[] propriedades = new NamedValue[2];
            propriedades[0] = Utils.createNamedValue(PROP_QNAME_MY_PROPERTY_TIPO.toString(), value);
            propriedades[1] = Utils.createNamedValue(PROP_QNAME_MY_PROPERTY_NUMERO.toString(), value);
            System.out.println("Constants: "+Constants.PROP_DESCRIPTION);
           
            CMLUpdate update = new CMLUpdate();
            update.setWhere(predicate);
            update.setProperty(propriedades);
           
            CML cmlUpdate = new CML();
            cmlUpdate.setUpdate(new CMLUpdate[]{update});
            //perform a CML update
            WebServiceFactory.getRepositoryService().update(cmlUpdate);
           
        } catch (InvalidNodeRefException e) {
            System.out.println("Erro: " + e);
        }
    }

Thanks for all or nothing.