BUG Community

Welcome! Log In

Forums BUG SDK java.lang.NoClassDefFoundError on startup

Subscribe to java.lang.NoClassDefFoundError on startup  13 posts, 4 voices

Log in to reply to this topic
 
May 4, 2008 9:55am
Img_missing_medium Tuxinator 6 posts

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:


java.lang.NoClassDefFoundError: com/buglabs/application/AbstractServiceTracker
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at ch.ethz.iks.concierge.framework.BundleClassLoader.findOwnClass(BundleClassLoader.java:630)
at ch.ethz.iks.concierge.framework.BundleClassLoader.findClass(BundleClassLoader.java:567)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
at carbug.Activator.start(Activator.java:20)
at ch.ethz.iks.concierge.framework.BundleImpl.startBundle(BundleImpl.java:446)
at ch.ethz.iks.concierge.framework.Framework$SystemBundle.setLevel(Framework.java:2464)
at ch.ethz.iks.concierge.framework.Framework$SystemBundle.access$0(Framework.java:2424)
at ch.ethz.iks.concierge.framework.Framework.startup(Framework.java:484)
at ch.ethz.iks.concierge.framework.Framework.main(Framework.java:314)
Caused by: java.lang.ClassNotFoundException: com.buglabs.application.AbstractServiceTracker
at ch.ethz.iks.concierge.framework.BundleClassLoader.findClass(BundleClassLoader.java:600)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
... 13 more
org.osgi.framework.BundleException: Error starting bundle Bundle [16]: file:/C:/Users/Me/workspace/.metadata/.plugins/com.buglabs.osgi.concierge.runtime/bundles/CarBug_1.0.0.jar
at ch.ethz.iks.concierge.framework.BundleImpl.startBundle(BundleImpl.java:460)
at ch.ethz.iks.concierge.framework.Framework$SystemBundle.setLevel(Framework.java:2464)
at ch.ethz.iks.concierge.framework.Framework$SystemBundle.access$0(Framework.java:2424)
at ch.ethz.iks.concierge.framework.Framework.startup(Framework.java:484)
at ch.ethz.iks.concierge.framework.Framework.main(Framework.java:314)


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:


public void start(BundleContext context) throws Exception {
//Create the service tracker and run it.
ctc = new CarBugServiceTracker(context);
Filter f = context.createFilter(ServiceFilterGenerator.generateServiceFilter(ctc.getServices()));
st = new ServiceTracker(context, f, ctc);
st.open();
}

/*
* (non-Javadoc)
* @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
*/
public void stop(BundleContext context) throws Exception {
ctc.stop();
}


Any help appriciated.
May 4, 2008 2:49pm
Medium Bug Labs team kschultz 107 posts

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.

May 4, 2008 9:09pm
Img_missing_medium Tuxinator 6 posts

kschultz
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?
May 5, 2008 3:07pm
Img_missing_medium akravets 25 posts

Hey Tuxinator,


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?


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/.
May 5, 2008 4:39pm
Medium Bug Labs team kschultz 107 posts

Tuxinator

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.


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.
May 5, 2008 5:34pm
Img_missing_medium akravets 25 posts

Yeah, debugger in Eclipse is just great, a real time saver. I don’t know what I would be doing without it :)
Also, just an FYI if you are going to read OSGi specifications – we are at release 3.

May 6, 2008 8:37pm
Img_missing_medium Tuxinator 6 posts

akravets

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/.


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:



public class Activator implements BundleActivator {

private CarBugServiceTracker stc;
private ServiceTracker st;

public void start(BundleContext context) throws Exception {
// TODO Auto-generated method stub
stc = new CarBugServiceTracker(context);

/*Filter f = context.createFilter(ServiceFilterGenerator.generateServiceFilter(stc.getServices()));
st = new ServiceTracker(context, f, stc);
st.open();*/

System.out.println("activator started");
}

public void stop(BundleContext context) throws Exception {
// TODO Auto-generated method stub
//stc.stop();
System.out.println("activator stopped");
}
}


and my ServiceTracker class:


public class CarBugServiceTracker extends AbstractServiceTracker {

private CarBugApp application;

public CarBugServiceTracker(BundleContext context) {
super(context);
}

/**
* Determines if the application can start.
*/
public boolean canStart() {
return super.canStart();
}

/**
* If canStart returns true
* this method is called to start the application.
* Place your fun logic here.
*/
public void doStart() {
System.out.println("starting");
}

/**
* Called when a service that this application depends is unregistered.
*/
public void doStop() {
System.out.println("stopping");
}

/**
* Allows the user to set the service dependencies by
* adding them to services list returned by getServices().
* i.e.nl getServices().add(MyService.class.getName());
*/
public void initServices() { //getServices().add("com.buglabs.bug.module.lcd.pub.IModuleDisplay");
}
}


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:

stc = new CarBugServiceTracker(context);

and it doesn't print "activator started" which is the last line in the start() method of the Activator class.

kschultz

he 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.


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?
May 6, 2008 9:53pm
Medium Bug Labs team finsprings 268 posts

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.)

May 7, 2008 7:27am
Img_missing_medium Tuxinator 6 posts

finsprings
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.
May 7, 2008 9:32am
Medium Bug Labs team kschultz 107 posts


kschultz

he 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.


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?


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.
May 7, 2008 1:26pm
Img_missing_medium akravets 25 posts

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.
May 8, 2008 10:27am
Img_missing_medium Tuxinator 6 posts

[quote="kschultz"]

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.


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.
akravets

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.


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?
May 8, 2008 10:47am
Medium Bug Labs team kschultz 107 posts

Tuxinator

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.
Log in to reply to this topic
Forums BUG SDK java.lang.NoClassDefFoundError on startup

Powered by Community Engine

Top
Login
Close
Bottom