Saturday, June 8, 2013

java.lang.NoClassDefFoundError - Android Development

Given that you have exported an existing project and try to run your android project via an emulator or your mobile phone,  and it seems to work just fine meaning that there is no compile time error or something and UI seems ok.  However when you click a button on the screen, suddenly you get such an error : "java.lang.NoClassDefFoundError in Android Development"

Do not worry ! There is always a reason behind the problem :)  It is actually about one of your jar files which cannot be found on runtime while JVM can find it in compile time.  If you are sure that your x.jar file is properly imported in your project in terms of its path, then there is one more thng you need to check.

 Ok our jar file seems ok, no error mark or something makes us guilty around our jar file :)
Then you should go to "Order and Export" tab as well.  And make sure that your jar file "BioHarnessBT.jar" in this case is checked !  If it is checked , run it and enjoy the result :)  and let all stress go away :)

Wednesday, June 5, 2013

Missing required library

It is actually an easy problem to solve. When you import an existing project into your workspace, you may face with such a problem since one of your jar files could not be found by the builder. That's why, some of the lines of codes are marked with red warning and try to warn you " I CANNOT FIND THE LIBRARY THAT YOU CLAIMED TO BE ON THE GIVEN PATH! "

Simply, right click your main project folder and go to properties. Then on the left menu find -> Java Build Path. Click Libraries tab and check the path of the jar file that most probably has a different path than the folder you have unzipped your project.rar.     Click edit and give the right path. Your problem has been solved ;)

Friday, May 4, 2012

Dynamically increasing int value on JFrame

I was trying to have a counter in the shape of jLabel on the JFrame that increases its value automatically .

My purpose was to mimic a heart rate of a person so that I would follow further operations based on this value.   I created an arrayList and made it full of integer heart rate values previously recorded in a txt  file. By using SwingWorker class defined in this example,  I was able to get an integer from the list, send it (by publish function) and catch it on the air and write it into label.  By this way I had an application that shows me the hearRate of a person as if it is in real time.

Check this Flipper example. 

Code explanation

Friday, April 27, 2012

Java tips 1 = Three dots ...

 Variable Length Arguments -

The cal method has a parameter "a" that is an integer.
But the trick is "..." three dots, meaning that  a is actually an integer array with unknown size. Btw, I can send 5 parameters, 10 ,400 ,500  , it doesnt matter.

public class shama {
    public static void main(String[] args) {
    public static void cal (int...a)
       for(int x:a)
         System.out.println("vals: " + x);

Result ; 

vals: 15
vals: 24
vals: 32
vals: 1
vals: 2
vals: 5
vals: 3
vals: 242
vals: 52