This sounds like a ThreadContextClassloader (TCL) problem.
Not sure about the sample you are using but usually you can get
arround this setting TCL to "null" when creating the framework:
Thread.currentThread().setContextClassLoader( null );

Make you reset it when you are done (getContextClassLoader(..))

Reason behind this: Classes
(tutorial.example2b.Activator$DictionaryImpl) exist twice (at least)
in your case: once in the host (where you start felix) and once in the
bundle.

Chances are also that you have to delegate the packages from the
system bundle, but that should have been part of the tutorial you are
using/referring to.
Toni

On Mon, Feb 22, 2010 at 5:52 PM, pablomj <pablom...@hotmail.es> wrote:
>
> Good day Karl,
>
> I also proved
> ds=(DictionaryService) bc.getService(sb[j]);
> but also generates a class exception.
>
> 02-22 16:47:14.794: DEBUG/Felix(2365): Could not create framework:
> java.lang.ClassCastException: tutorial.example2b.Activator$DictionaryImpl
>
> I'm sorry. I know that it is maybe an OSGi problem...but I think that maybe
> someone here could help me.
> I continue with this. Thank you for answer,
> Pablo.
>
>
>
>
>
> Karl Pauls wrote:
>>
>> You are trying to cast a servicereference to a service object. That
>> doesn't work. You need to first get the real service by:
>>
>> bc.getService(sb[j]);
>>
>> Nothing to do with android btw. - just osgi.
>> regards,
>>
>> Karl
>>
>> On Mon, Feb 22, 2010 at 4:28 PM, pablomj <pablom...@hotmail.es> wrote:
>>>
>>> Good day, I trying embedding Felix in Android. I installed some bundles
>>> (English Dictionary, French Dictionary, Spellchecker...). Well, the
>>> program
>>> compiles but I can't instanciate a DictionaryService for use for example
>>> d.checkword("the");
>>>
>>> The code is:
>>>
>>>
>>> try {
>>> m_felix.start();
>>>
>>> BundleContext bc=m_felix.getBundleContext();
>>>            bc.installBundle("file:/data/felix/EnglishDictionary.jar");
>>>            bc.installBundle("file:/data/felix/FrenchDictionary.jar");
>>>            bc.installBundle("file:/data/felix/SpellChecker.jar");
>>>
>>> //start all bundles
>>> org.osgi.framework.Bundle[] bs=bc.getBundles();
>>> for(int i=0; i<bs.length; i++) { bs[i].start(); }
>>>
>>> //get registered services
>>> ServiceReference[]
>>> sb=bc.getAllServiceReferences("tutorial.example2.service.DictionaryService","(Language=*)");
>>>
>>> ServiceReference[]
>>> sb=bc.getAllServiceReferences("tutorial.example2.service.DictionaryService","(Language=*)");
>>>
>>>                if(sb !=null)
>>>                {
>>>                        for(int j=0;j<sb.length; j++)
>>>                        {
>>>                                Log.d("FELIX","registered services:
>>> "+sb[j].toString());
>>> ERROR --------------->DictionaryService d=(DictionaryService) sb[j];
>>>                                boolean b=d.checkWord("the");
>>>                        }
>>>                }
>>>                else
>>>                {
>>>                        Log.d("FELIX","No registered services");
>>>                }
>>> }
>>> catch { ... }
>>>
>>>
>>> The log is:
>>> 02-22 15:06:30.734: DEBUG/FELIX(759): registered services:
>>> [tutorial.example2.service.DictionaryService]
>>> 02-22 15:09:51.754: DEBUG/Felix(863): Could not create framework:
>>> java.lang.ClassCastException:
>>> org.apache.felix.framework.ServiceRegistrationImpl$ServiceReferenceImpl
>>>
>>>
>>> Somebody can help me for make an instance of a service? I don't know how
>>> I
>>> can obtain it. Thanks,
>>> Pablo
>>>
>>> --
>>> View this message in context:
>>> http://old.nabble.com/Felix-embeded-in-Android---problem-for-instantiate-a-Service.-tp27688984p27688984.html
>>> Sent from the Apache Felix - Dev mailing list archive at Nabble.com.
>>>
>>>
>>
>>
>>
>> --
>> Karl Pauls
>> karlpa...@gmail.com
>>
>>
>
> --
> View this message in context: 
> http://old.nabble.com/Felix-embeded-in-Android---problem-for-instantiate-a-Service.-tp27688984p27690380.html
> Sent from the Apache Felix - Dev mailing list archive at Nabble.com.
>
>



-- 
Toni Menzel
Independent Software Developer
Professional Profile: http://okidokiteam.com
t...@okidokiteam.com
http://www.ops4j.org     - New Energy for OSS Communities - Open
Participation Software.

Reply via email to