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

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,
Bitmap.Config.ARGB_8888);

java.lang.RuntimeException: Stub!
    at android.graphics.Bitmap.createBitmap(Bitmap.java:27)
    at
uk.ac.ic.doc.gea05.miffed.operators.concreteoperators.binary.TestIdentityTransform.generateBitmap(TestIdentityTransform.java:60)

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!

Gav






--~--~---------~--~----~------------~-------~--~----~


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
(samples/ApiDemos/tests/)

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

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
http://developer.android.com/reference/android/test/InstrumentationTestRunner.html

Xav

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;

File
New
Android Project
Create new android project
Create Project from existing source
android/android-sdk-linux_x86-1.1_r1/samples/ApiDemos/tests

! No activity name defined in
/home/gavin/Work/android/android-sdk-linux_x86-1.1_r1/samples/ApiDemos/tests/AndroidManifest.xml.

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,

Gavin

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


--~--~---------~--~----~------------~-------~--~----~



Other Threads

1. adb devices command sees multiple offline devices attached - but it's the same device

Hi all
Is there a way to clear the list of devices?

What I'm seeing:
$ adb devices
List of devices attached
HT842GZ47827    offline
HT842GZ47827    offline
HT842GZ47827    offline
HT842GZ47827    offline
HT842GZ47827    offline
HT842GZ47827    offline
HT842GZ47827    offline
HT842GZ47827    offline
HT842GZ47827    device

I've tried restarting the phone but the 'offline' entries don't go
away.  This is making it impossible to initiate a shell or logcat:
$ adb shell
error: more than one device and emulator

Is there a way to do this without rebooting my computer.

Thanks


--~--~---------~--~----~------------~-------~--~----~

2. SDCard and SQLiteOpenHelper problem

Hello,

I need to be able to work with databases on the sdcard.

I've been using the following code snippet from the NotePad
application and works perfectly on the emulator without using the
sdcard.

private static class DatabaseHelper extends SQLiteOpenHelper {
DatabaseHelper(Context context) {
super(context, "mydb.sqlite", null, 2);
}

When I include the path to the db as
 "/sdcard/application/mydb.sqlite"

the following error occurs
 10-29 09:57:04.798: ERROR/AndroidRuntime(200): Caused by:
java.lang.IllegalArgumentException: File /sdcard/application/
mydb.sqlite contains a path separator

The sdcard is properly emulated.
The path exists.

I've looked around but no obvious solution to me.

Any help greatly appreciated.

Cheers,
Wes

--~--~---------~--~----~------------~-------~--~----~

3. : How to stops the activity from getting restarted when mode changes from LandScape to Portrait or vice-versa

4. activity doesn't seem to end, despite calling .finish()...

5. "Wiring" emulator services to PC's

6. Carrymobile 's HTC Dream/T-Mobile G1/Google Andriod leather case released

7. pop3