NoClassDefFoundError with custom service configuration

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

NoClassDefFoundError with custom service configuration

lbelloq
I'm writing a sample UPnP browse app and followed the manual and browser examples, but the app crashes as soon as it starts.

Code as follows.

Service connection:
private ServiceConnection serviceConnection = new ServiceConnection() {

        public void onServiceConnected(ComponentName className, IBinder service) {
            upnpService = (AndroidUpnpService) service;

            listAdapter.clear();
            upnpService.getRegistry().addListener(registryListener);
            for (Device device : upnpService.getRegistry().getDevices()) {
                registryListener.deviceAdded(device);
            }
            upnpService.getControlPoint().search();
        }

        public void onServiceDisconnected(ComponentName className) {
            upnpService = null;
        }
    };

onCreate() of my activity:
@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        listAdapter = new ArrayAdapter<DeviceDisplay>(this, android.R.layout.simple_list_item_1);
        ListView hostsList = (ListView) findViewById(R.id.lstHosts);
        hostsList.setAdapter(listAdapter);

        getApplicationContext().bindService(
                new Intent(this, CustomClingClass.class),
                serviceConnection,
                Context.BIND_AUTO_CREATE
        );

        hostsList.setOnItemClickListener(new OnItemClickListener() {

            @SuppressWarnings({"rawtypes", "unchecked"})
            @Override
            public void onItemClick(AdapterView<?> parent, View v, int position, long arg3) {
                DeviceDisplay selectedDevice = (DeviceDisplay) parent.getItemAtPosition(position);
                Toast.makeText(MainActivity.this, "Test", Toast.LENGTH_SHORT);
            }
        });
    }

CustomClingClass:
import org.fourthline.cling.UpnpServiceConfiguration;
import org.fourthline.cling.android.AndroidUpnpServiceConfiguration;
import org.fourthline.cling.android.AndroidUpnpServiceImpl;
import org.fourthline.cling.model.types.ServiceType;
import org.fourthline.cling.model.types.UDAServiceType;

public class CustomClingClass extends AndroidUpnpServiceImpl {

    @Override
    protected UpnpServiceConfiguration createConfiguration() {
        return new MyUpnpServiceConfiguration() {

            @Override
            public int getRegistryMaintenanceIntervalMillis() {
                return 7000;
            }

            @Override
            public ServiceType[] getExclusiveServiceTypes() {
                return new ServiceType[]{
                        new UDAServiceType("DHTestControl")
                };
            }
        };
    }
}

MyUpnpServiceConfiguration:
import org.fourthline.cling.DefaultUpnpServiceConfiguration;
import org.fourthline.cling.android.AndroidUpnpServiceConfiguration;
import org.fourthline.cling.model.Namespace;
import org.fourthline.cling.transport.spi.NetworkAddressFactory;
import org.fourthline.cling.transport.spi.StreamClient;
import org.fourthline.cling.transport.spi.StreamServer;

public class MyUpnpServiceConfiguration extends AndroidUpnpServiceConfiguration {

    @Override
    protected Namespace createNamespace() {
        return new Namespace("/upnp"); // This will be the servlet context path
    }

    @Override
    public StreamClient createStreamClient() {
        return new org.fourthline.cling.transport.impl.jetty.StreamClientImpl(
                new org.fourthline.cling.transport.impl.jetty.StreamClientConfigurationImpl(
                        getSyncProtocolExecutorService()
                )
        );
    }

    @Override
    public StreamServer createStreamServer(NetworkAddressFactory networkAddressFactory) {
        return new org.fourthline.cling.transport.impl.AsyncServletStreamServerImpl(
                new org.fourthline.cling.transport.impl.AsyncServletStreamServerConfigurationImpl(
                        org.fourthline.cling.transport.impl.jetty.JettyServletContainer.INSTANCE,
                        networkAddressFactory.getStreamListenPort()
                )
        );
    }
}

Error and stacktrace:
    java.lang.NoClassDefFoundError: org.fourthline.cling.transport.impl.AsyncServletStreamServerImpl$1
            at org.fourthline.cling.transport.impl.AsyncServletStreamServerImpl.createServlet(AsyncServletStreamServerImpl.java:96)
            at org.fourthline.cling.transport.impl.AsyncServletStreamServerImpl.init(AsyncServletStreamServerImpl.java:74)
            at org.fourthline.cling.transport.RouterImpl.startAddressBasedTransports(RouterImpl.java:434)
            at org.fourthline.cling.transport.RouterImpl.enable(RouterImpl.java:132)
            at org.fourthline.cling.android.AndroidRouter.enable(AndroidRouter.java:92)
            at org.fourthline.cling.UpnpServiceImpl.<init>(UpnpServiceImpl.java:87)
            at org.fourthline.cling.android.AndroidUpnpServiceImpl$1.<init>(AndroidUpnpServiceImpl.java:54)
            at org.fourthline.cling.android.AndroidUpnpServiceImpl.onCreate(AndroidUpnpServiceImpl.java:54)
            at android.app.ActivityThread.handleCreateService(ActivityThread.java:2763)
            at android.app.ActivityThread.access$1800(ActivityThread.java:148)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1375)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5312)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:901)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:696)

I can't actually find what I'm doing wrong. Thanks for your help.