Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » Eclipse SmartHome » NoClassDefFoundError when using ManagedItemProvider.add in custom binding
NoClassDefFoundError when using ManagedItemProvider.add in custom binding [message #1768061] Thu, 13 July 2017 10:58 Go to next message
Thomas Biacsics is currently offline Thomas BiacsicsFriend
Messages: 3
Registered: June 2016
Junior Member

I am getting errors when I use the ManagedItemProvider.add method.
In order to be able to call ManagedItemProvider.add and build my custom binding, I have to import the package "org.eclipse.smarthome.core.common.registry".

Then I dont have any compile errors anymore, but when I start the application (openHAB2) I get the following errors in the console:

!ENTRY org.eclipse.equinox.ds 4 0 2017-07-13 12:29:48.311
!MESSAGE Exception occurred while creating new instance of component Component[
	name = binding.irrigationsystem2
	activate = activate
	deactivate = deactivate
	modified = 
	configuration-policy = optional
	factory = null
	autoenable = true
	immediate = true
	implementation = org.openhab.binding.irrigationsystem2.internal.IrrigationSystem2HandlerFactory
	state = Unsatisfied
	properties = 
	serviceFactory = false
	serviceInterface = [org.eclipse.smarthome.core.thing.binding.ThingHandlerFactory]
	references = null
	located in bundle = org.openhab.binding.irrigationsystem2_2.2.0.qualifier [79]
java.lang.NoClassDefFoundError: Could not initialize class org.openhab.binding.irrigationsystem2.internal.IrrigationSystem2HandlerFactory
	at sun.reflect.GeneratedConstructorAccessor10.newInstance(Unknown Source)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
	at java.lang.reflect.Constructor.newInstance(Unknown Source)
	at java.lang.Class.newInstance(Unknown Source)
	at org.eclipse.equinox.internal.ds.model.ServiceComponent.createInstance(
	at org.eclipse.equinox.internal.ds.model.ServiceComponentProp.createInstance(
	at org.eclipse.equinox.internal.ds.InstanceProcess.buildComponent(
	at org.eclipse.equinox.internal.ds.InstanceProcess.buildComponents(
	at org.eclipse.equinox.internal.ds.Resolver.buildNewlySatisfied(
	at org.eclipse.equinox.internal.ds.Resolver.enableComponents(
	at org.eclipse.equinox.internal.ds.SCRManager.performWork(
	at org.eclipse.equinox.internal.ds.SCRManager$QueuedJob.dispatch(
	at Source)

The function call to "ManagedItemProvider.add" is definitly crashing my binding. If I comment the call out, the binding starts without errors.

I need the ManagedItemProvider within my binding because I am creating Items at runtime.

Since I updated my Application from openHAB 2.0 to 2.2, the Eclipse SmartHome Version also changed and then the ManagedItemProvider.add does not work anymore.

What did I forget to import or include within my binding?


PS: I hope that my post is here right in this forum. Or should I have post it to openHAB forum?
Re: NoClassDefFoundError when using ManagedItemProvider.add in custom binding [message #1768063 is a reply to message #1768061] Thu, 13 July 2017 11:05 Go to previous messageGo to next message
Simon Kaufmann is currently offline Simon KaufmannFriend
Messages: 51
Registered: January 2011
As your question is about usage of Eclipse SmartHome APIs, this forum is the perfect place for it.

From the stacktrace you posted it is hard to guess what might have gone wrong - your IrrigationSystem2HandlerFactory cannot be instantiated, but the root-cause is not clear.

In any case... What your are trying to do sounds highly unusual to me. Items are maintained by the users of the system and bindings should never ever mess around with them. Things & Channels are the entities that bindings should work with. Maybe you could explain what you actually want to achieve, then I'm pretty sure we will figure out a good way how it could be implemented in your binding?
Re: NoClassDefFoundError when using ManagedItemProvider.add in custom binding [message #1768092 is a reply to message #1768063] Thu, 13 July 2017 14:12 Go to previous messageGo to next message
Thomas Biacsics is currently offline Thomas BiacsicsFriend
Messages: 3
Registered: June 2016
Junior Member
That's right, but I was not able to find the real root cause. I can only say that when I make a call to "ManagedItemProvider.add()", the whole binding can not be initialised.

I know that the intention of an item is not that as I want to use them. I want to implement the following features in order to the users don't have to add items manually and assign ids or create links --> the binding should do that tasks for the user and sets up the items automatically.

My binding implements a DiscoveryService which searches for wireless irrigation devices . When a device was found, one bridge (Irrigation Device) and 5 Things (Irrigation Valves) are created.
Then I want to create also the "User Interface" automatically for the user. In order to accomplish that I created a few fixed GroupItems, for example "gAllDevices", and added them to the Sitemap. So when the bridge and the things are added, I want to create within this process also nested Items which then automatically build the user interface for the newly added bridge and things.
In short, I want to build a user interface (forms for creating database entries (for example a schedule entry for an irrigation valve, or forms for starting a manual irrigation task) with the use of items and GroupItems.

A sample structure would look like this:

gAllDevices --> gDevice1, gDevice2, ...
gDevice1 --> gValve1, gValve2, ...
gValve1 --> gManualIrrigation, gAddScheduleEntry, some statusItems, gShowAllScheduleEntries
gManualIrrigation --> durationItem, starttimeItem, submitButtonItem, ...
gAddScheduleEntry --> monday, tuesday, ... , starttime, endtime, ... , saveButton

If I can not achieve this programatically with the usage of items, the whole discovery and thing adding process will not take effect on the user interface. The main purpose is, that the user only has to search for things, add the things and afterwards the sitemap and items are already created and the user don't has to care about creating and linking items manually in order to have an useful user interface within the sitemap.

Maybe openHAB or ESH is the wrong tool for implementing such an application scenario but I wanted to use it because of other useful bindings and the good infrastructure.

So what do you think? :)
Thanks, Thomas
Re: NoClassDefFoundError when using ManagedItemProvider.add in custom binding [message #1768180 is a reply to message #1768092] Fri, 14 July 2017 11:50 Go to previous message
Simon Kaufmann is currently offline Simon KaufmannFriend
Messages: 51
Registered: January 2011
No, ESH and openHAB are perfectly fine for implementing such a scenario. I know at least one other big commercial solution built on top of ESH that also hides the items/sitemap hassle from its users and creates manages them auto-magically. So it's perfectly fine to manage them automatically. The only thing that irritated me was that your binding is doing it. If you want to keep your binding to yourself, you are of course free to do whatever you like in there. If you however decide to contribute this to any of the open source projects, you should rather keep these concerns separate, in a different bundle. And I would recommend doing it anyway.

By the way: What ESH (and also openHAB) has is a so called "simple mode" a.k.a. "auto-linking". If enabled, the ThingLinkManager will automatically create links for all channels automatically and subsequently items for all links pointing to items which don't exist otherwise. So you will get the item/link creation (and removal!) part "for free" from the framework if your like. Your can enable/disable it in the PaperUI (Configuration -> System -> Item Linking -> Simple Mode) or via a config file "conf/services/org.eclipse.smarthome.links.cfg" with a "autoLinks=true" content. Then you will only need to take care of your group items in order to add those items as children automatically. I would suppose the easiest way of doing it is registering your own service component to the ItemRegistry as a RegistryChangeListener so you will get notified whenever an item gets added or removed. I have to admit that ESH currently at this point is a little weak, because you cannot provide sitemaps independently from the *.sitemap files, e.g. via java code. There have been thoughts on this here, but the discussion ceased and so far wasn't picked up again.

If you don't want to use the auto linking, you could still fall back to registering your component to the ThingRegistry, again as a RegistryChangeListener. Then you can handle item/link creation/deletion whenever one of your relevant things show up or disappear. You then have to ways to go: add the items/links that you maintain to the corresponding managed providers (i.e. rely on the database backed one), or make your service component implement the ItemProvider/ItemChannelLinkProvider interfaces so that the registries pick them up. The latter is probably more work on your side, but on the other hand you are by yourself there and have no users messing around with your entities.

Hope that helps?
Previous Topic:The io.transport.mqtt implementation is too restrictive
Next Topic:Problems in creation the development environment
Goto Forum:

Current Time: Sat May 18 07:24:55 GMT 2024

Powered by FUDForum. Page generated in 0.03542 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top