|
|
Re: Why reflection doesn't work in rap [message #507635 is a reply to message #507596] |
Thu, 14 January 2010 08:23 |
Rüdiger Herrmann Messages: 581 Registered: July 2009 |
Senior Member |
|
|
RAP is based on Equinox, the Eclipse OSGi implementation. In OSGi each
bundle has its own class loader, this is probably what causes the trouble.
If you are working with class loaders, make sure that you understand the
technologies that are involved [1]. Searching for "osgi class loading"
should bring up enough material.
The reason why the unit tests are working is that they are executed as a
plain Java application (no OSGi involved).
HTH
Rüdiger
[1] http://eclipse.org/rap/documentation.php#resources
--
Rüdiger Herrmann
http://eclipsesource.com
On 14.01.2010 01:59, chen_jiahang@hotmail.com wrote:
> Hi,
> In rap, I try to use reflection to load a class by its classpath and
> classname. When I test it in junit, it work good. But when I call this
> method from UI, it always give me a ClassCastException
>
> My code:
>
> /** The reference to a data processing object, is loaded as an Algorithm
> (see RunAlgorithm) */
> protected DataProcessing dataProcessing;
>
> /** Reference to class of Algorithm used in this activity */
> private Class<? extends DataProcessing> dpClass;
>
> AlgorithmLoader algorithmLoader = new AlgorithmLoader();
> algorithmLoader.addPath(dpClassPath);
> dpClass = (Class<? extends DataProcessing>)
> algorithmLoader.loadClass(dpClassName);
> dataProcessing = dpClass.newInstance();
>
> Exception is : java.lang.ClassCastException:
> ianalyst.algorithm.dataprocessing.rowoperation.Sampling cannot be cast
> to ianalyst.algorithm.dataprocessing.DataProcessing
> ..............
> ............
>
> algorithmLoader extend from URLClassLoader.
> Sampling extend from DataProcessing.
>
>
> Can some one give me some idea, thank you very much
>
|
|
|
Powered by
FUDForum. Page generated in 1.38701 seconds