|
|
I was using the "SimpleGUI" app as my guide to constructing my app with the LCD module but I get this error and from what I can tell it's a Bug SDK related error:This does not happen in the "SimpleGUI" app I downloaded and if I comment out my code in the start() method in my Activator class it doesn't throw this error so I'm guessing it's something wrong with my code. My Activator code looks like this: Any help appriciated. |
|
|
Generally I do not touch anything in the activator class. I have so far been able to create all my apps leaving the activator class as boilerplate I don’t mess with. Exceptional cases may arise, but so far I think the best practice is to make the hook to your actual application from the doStart() method of the service tracker class. Activator basically runs when you start up the bundle, and it is sitting on the BUG but doesn’t have the modules it needs yet. Once the OSGi runtime knows that you have all the modules/services you need, it calls the doStart() method. By commenting out the start() method in the activator, it is never even registering with the OSGi runtime in the first place. So the code is further down the codes path, do you want to post more code? Or maybe just upload it to bugnet and I can look at it. |
|
|
Thanks for your reply. I haven't read all of the OSGI "About the OSGi Service Platform" white paper yet so sorry if it's covered in that topic. From your reply does that mean I can have an empty start method in the Activator class and just start my applications in the service tracker? Looking at the code samples there are usually instantiations for the service tracker like in the second quote in my first post. The error points the fault at line 20 in my Activator class which is: ctc = new CarBugServiceTracker(context);the first line in my start method in the Activator class. Also are there any articles describing the architecture and process of a program for the bug like you mentioned the doStart() is called when all the services / modules exists? |
|
|
Hey Tuxinator, That's right. The work that your application is doing will happen in the service tracker. The start() method in Activator should not be empty though because it does an import work of starting the tracker. By starting tracker in the Activator you basically saying that I need these services to run my application, let tracker do the tracking of the services. When services needed are available, tracker's doStart() method will be called and your application will start. You can "see" how this works by placing a brake point in the tracker's doStart() method and when services for particular application are available, stepping through the code. Also, since bug applications are really OSGi bundles they work just like OSGi bundles. Thus you can get OSGi specification from http://www.osgi.org/Specifications/HomePage and read first few chapters to get familiar with the framework. Since reading specifications could be a bit daunting for some people, Neil Bartlett did everyone a huge favor by starting writing his own book on OSGi, you can find the latest chapters here: http://neilbartlett.name/blog/osgibook/. |
|
|
Don't worry, I couldn't really make it through the OSGi spec either. The way that Dragonfly generates the Activator class is all you will need. The start method had some stuff in it, but don't worry about editing it. It is autogeneratered, and later on you can look at it and understand it but for now it is unimportant. Alex is right about the break point, often times you will get errors that point to places other than where they are actually failing. It is definately worth the time to learn how to use the Eclipse debugger, I had never used an IDE debugger before writing my BUG apps but it was a HUGE time saver and is helping me a lot this semester now that I am writing much more complex programs at school. This tutorial helps although it has about 5 times more techniques than you probably need. http://www.linuxdevices.com/articles/AT6046208714.html If I have a program that is crashing during execution I set a break point before where the failure is occuring, and then just step over lines and step into functions until I find where it crashes. If I have a program that runs but is giving me the wrong output, I set a break point and step over and into stuff while watching the values of the variables change. Thats really all there is to it, but it is amazingly powerful. |
|
|
Yeah, debugger in Eclipse is just great, a real time saver. I don’t know what I would be doing without it :) |
|
|
Great stuff thanks for the link. I understand the framework a bit better now but I'm still having problems. Here is my Activator class: and my ServiceTracker class: Most of the code doesn't do anything but print to console but I still get the error " java.lang.NoClassDefFoundError" which I posted in my first post. The error occurs when I'm instantiating the ServiceTracker class: and it doesn't print "activator started" which is the last line in the start() method of the Activator class. Your IDE generates the code for you? When I created my project using the Dragonfly perspective in Eclipse it only generated the start() and stop() methods but they are empty with a TODO comment. Is this right because it sounds like your IDE fills it in for you? |
|
|
Check your app’s MANIFEST.MF (it’s under META-INF). If you click on the last tab, also named MAINFEST.MF, do you see com.buglabs.application in the Import-Package section? If not, add it and try running your application again. (I took a functioning application, removed that entry from my manifest and got the exact same class error you have when I ran it.) |
|
|
Thank you. It was the manefest problem and it didn't have the import-package statement. |
|
|
Ok I know where all this is stemming from then, when you create a new project there is a list of services in the center of the screen, you have to highlight the modules you want. So there is a button to start a Virtual BUG, you plug in the modules you want your app to use, and Dragonfly will generate all the OSGi based on that. I think there are detailed instructions somewhere, I'm on a computer without Dragonfly installed so I can't give you detailed directions at the moment. This is a common mistake I make when I'm rushing I skip right over that and end up with just an activator class. The activator, manifest.mf, and the servicetracker should all be generated for you and then all you have to do is hook into your application from the doStart() method of the servicetracker. |
|
|
Here are the instructions on what Kevin was talking about: http://bugcommunity.com/wiki/index.php/Create_a_basic_application_with_the_Motion_Sensor_module Also, the reason service tacker is there is so your application can run when certain requirements exist. For example, let say in order for service A to function property service B must be present in the system. If I try to execute service A without B present then my application will not work. But if I have a service tracker that will track for presence of service B, then when service B becomes available my service A will be happy and do its thing. |
|
|
[quote="kschultz"]
I see your point. When I created the project I gave it a name clicked on finish instead of next. The following screen is very good in allowing you to select and generate the classes for you. Maybe in future releases disabling the finish button until you get to the last screen? If people only want to create an empty project they can just click next and then finish without starting the Virtual Bug and selecting the services.
Is this true for when a service becomes unavailable as well but instead of calling start it would call stop? I take it services can include software and hardware services? |
|
|
Correct, that is how the modules can be hot swapable, because the OSGi stuff handles the "life cycle" management. OSGI services can be hardware or software. A good example is my GPSUtilities package, it is a software service accessed the same way as a hardware module (or really I guess the hardware modules work like software services since OSGi was first for software only). Also the services are independant of the hardware, i.e. we could create a IPositionProvider based on a technology other than GPS that would be possible, or if we wanted to create a module that had a camera and a GPS, both could be offered up by one module. For right now when there are only 4 modules and a handful of software services the OSGi stuff might not seem necessary, but when we have 50 modules and there are 100 software services on BUGnet it will be worth the added complexity because it allows software to be independent of the hardware configuration. |