JUnit and ClassNotFoundException

by Bo » Wed, 07 Jan 2009 18:26:59 GMT

Sponsored Links
 I am trying to run a unit test in Eclipse. I followed Android FAQ
( http://code.google.com/android/kb/troubleshooting.html #addjunit) to
get JUnit working. Unfortunately, it works only if tested code does
not reference any android classes. As soon as it does, I get the
following exception, when running the test (if the class in question
implements Parcelable):

Caused by: java.lang.ClassNotFoundException: android.os.Parcelable
        at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:316)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:288)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
        at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:374)
        ... 33 more

I tried including android.jar file explicitly, but then I got an
exception claiming that RectF (an instance variable in my class) is a
stub. Anybody knows how to setup Eclipse to run a unit test with
classes that either implement, extend or use android classes?


JUnit and ClassNotFoundException

by Gavin Aiken » Sat, 07 Mar 2009 05:25:09 GMT

 Hi Bo,

Did you resolve this issue? I'm having a similar problem.

My test suite is a separate eclipse project, I need to test my android
program against a desktop Java program in order to verify that I have ported
the application correctly.

To so this I need to use classes from both the JAI library and Android

My test package is currently setup as a java project, I assumed the JAI
library wouldn't compile to dex but that the android classes would compile
to java class files. I'm guessing that the latter is incorrect as any
methods I call return a stub error;

60.  return Bitmap.createBitmap(pixels, 0, width, width, height,

java.lang.RuntimeException: Stub!
    at android.graphics.Bitmap.createBitmap(Bitmap.java:27)

I'm presuming that I can't get this to work, and submit this comment for
reference. If there is a way to use Java Libraries in a test with android
api calls then please let me know!



Sponsored Links

JUnit and ClassNotFoundException

by Xavier Ducrohet » Sat, 07 Mar 2009 06:40:28 GMT

 he only way to test code that uses Android API is on a device or emulator.

Look at instrumentation projects such as the ApiDemos test project

You will need to create an Eclipse project for ApiDemos and one of the
test project.
ADT doesn't fully support this at this point, so you'll need to add
the ApiDemos project to the build path of the test project so that it

You then need to install both apk on the device, and use the "am
instrument ..." command on the device (through adb shell).
More information at


On Fri, Mar 6, 2009 at 1:24 PM, Gavin Aiken <gavin.ai...@imperial.ac.uk> wrote:

Xavier Ducrohet
Android Engineer, Google.


JUnit and ClassNotFoundException

by Gavin Aiken » Fri, 13 Mar 2009 17:19:46 GMT

 i Xav,

Thanks for the tip, I'm still having trouble setting up the test project;

Android Project
Create new android project
Create Project from existing source

! No activity name defined in

I understand that I have to add ApiDemos to the build path but I have to
create the project first. Apologies if this is a bit of a silly question, I
imagine the answer is right in front of me but I can't work it out.

Kind regards,


On Fri, Mar 6, 2009 at 10:40 PM, Xavier Ducrohet <x...@android.com> wrote:


Other Threads

1. EventHandler errors?

I am getting compiler error for EventHandle inheritance and I cannot
find a Javadoc reference for the calls.
does anyone know about these?

The type MyEventHandler must implement the inherited abstract method

Severity and Description        Path    Resource        Location        
Creation Time   Id

The type MyEventHandler2 must implement the inherited abstract method

The type MyEventHandler2 must implement the inherited abstract method


2. Drawable in XML referencing other drawables by state.

I found two interesting drawables in ApiDemos:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true" android:drawable="@drawable/
black_opaque_box" />
    <item android:drawable="@drawable/black_box" />

<layer-list xmlns:android="http://schemas.android.com/apk/res/
        android:drawable="@drawable/progress_circular_background" />

        android:drawable="@drawable/progress_particle" />

I found no documentation for this kind of drawable.

In ItemizedOverlay we can use drawables with state_focused is handled.
I tried to pass the following drawable (bubble.xml)

    android:drawable="@drawable/bubble_normal" />
    android:drawable="@drawable/bubble_focused" />

Unfortunately, my map always show bubble_normal even if there is a
focused item (I checked that).
I suppose I have to use another tag than <selector> but I didn't found
in the documentation which tag to use nor all possible tag list.

3. How to make my Form b transparent/Translucent background???

4. screen orientation values in Display class

5. Get the coordinates of screen when I touch it

6. Turn off Android mobile ??

7. HTC Dream/G1 Tmobile Preorder