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 <[email protected]> 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
[email protected]

Reply via email to