掲示板

Error cast using Service Builder

7年前 に Daniel Fernandez によって更新されました。

Error cast using Service Builder

Junior Member 投稿: 29 参加年月日: 17/03/29 最新の投稿
I,m using liferay 7 with Tomcat 8, i need to insert a product on my data base using Service Builder.

I,ve been searching on internet to do the insert method in my personal portlet that is in another package, i do all the dependencies and imports, and it really works, but when I run de project and execute my method i had an error like this:
(" java.lang.ClassCastException: com.sun.proxy.$Proxy470 cannot be cast to com.serviceBuilder.service.ProductoLocalService")


My codeemoticonThis code is in my personal porlet in module DatosPersonales)
Producto prod = ProductoLocalServiceUtil.createProducto(0); ("The error apears in this line")
prod.setCodigo("Codigo");
prod.setValor("Valor");
prod.setDescripcion("Descripcion");
prod.setID(1);
prod = ProductoLocalServiceUtil.addProducto(prod);

I think is all right, but when i execute my code this error apears.

It might be an error creating my Service Builder, but i thin is all right, the error apears in my class ProductoLocalServiceUtil, doing method createProducto();

My codeemoticonThis code is in module ServiceBuilder in my package com.serviceBuilder.service)
public static com.serviceBuilder.model.Producto createProducto(int ID) {
return getService().createProducto(ID); ("This line sends my to another method")
}

Another method:
public static ProductoLocalService getService() {
return _serviceTracker.getService();
}
In the lasth method i get the error in return, i think is not working properly and i don´t know why this error apears.

If you know how to solve it please help me and the comunity.

Thanks a lot, Best Regards.
thumbnail
7年前 に Andy Wu によって更新されました。

RE: Error cast using Service Builder

Regular Member 投稿: 195 参加年月日: 15/05/05 最新の投稿
I also met such error before but I can't recall what is exactly going on.
You can see following sample to find what is wrong with your code:
https://github.com/liferay/liferay-blade-samples/tree/master/liferay-workspace/modules
blade.servicebuilder.api
blade.servicebuilder.svc
blade.servicebuilder.web

And also , you could upload your project and we can try to reproduce it.

Regards.
7年前 に Daniel Fernandez によって更新されました。

RE: Error cast using Service Builder

Junior Member 投稿: 29 参加年月日: 17/03/29 最新の投稿
I've already watch this link before and it really don't work properly.

My error is been located in this method:
public static ProductoLocalService getService() {
return _serviceTracker.getService();
}

In fact, this method is called by another method:
public static com.serviceBuilder.model.Producto createProducto(int ID) {
return getService().createProducto(ID);
}
When i execute my code, the error apears because Eclipse cannot cast class ProductoLocalServiceUtil to ProductoLocalService, i don't know why.

When method strarts i cast ("Producto prod = ProductoLocalServiceUtil.createProducto();") I cast producto to ProductoLocalServiceUtil.
I think ServiceBuilder is prepared to cast those classes, because we need that those clases were be able to talk to each other.

What i need to do is insert these values to liferay data base with service builder. i think i'm doing properly if i'm doing in the wrong way please let me know.

Thank for you early reply Andy Wu.
7年前 に Daniel Fernandez によって更新されました。

RE: Error cast using Service Builder

Junior Member 投稿: 29 参加年月日: 17/03/29 最新の投稿
Andy Wu:
I also met such error before but I can't recall what is exactly going on.
You can see following sample to find what is wrong with your code:
https://github.com/liferay/liferay-blade-samples/tree/master/liferay-workspace/modules
blade.servicebuilder.api
blade.servicebuilder.svc
blade.servicebuilder.web

And also , you could upload your project and we can try to reproduce it.

Regards.


I've already watch this link before and it really don't work properly.

My error is been located in this method:
public static ProductoLocalService getService() {
return _serviceTracker.getService();
}

When i execute my code, the error apears because Eclipse cannot cast class ProductoLocalServiceUtil to ProductoLocalService, i don't know why.

When method strarts i cast ("Producto prod = ProductoLocalServiceUtil.createProducto();") I cast producto to ProductoLocalServiceUtil.
I think ServiceBuilder is prepared to cast those classes, because we need that those clases were be able to talk to each other.

What i need to do is insert these values to liferay data base with service builder. i think i'm doing properly if i'm doing in the wrong way please let me know.

Thank for you early reply Andy Wu.
thumbnail
7年前 に David H Nebinger によって更新されました。

RE: Error cast using Service Builder

Liferay Legend 投稿: 14919 参加年月日: 06/09/02 最新の投稿