JSONObject failing with Stub! error on 1.0-RC1

1,092 views
Skip to first unread message

Jeremy Wadsack

unread,
Apr 19, 2011, 12:54:24 PM4/19/11
to robol...@googlegroups.com
I'm trying to get Robolectric working and can't seem to get it to load the JSON library. Issue 4 and the related email thread on this list implies this was fixed in November, but I'm still getting the same problem.

Specifically, running my tests I get the following warnings and error:

Warning: an error occurred while binding shadow class: ShadowBluetoothAdapter
Warning: an error occurred while binding shadow class: ShadowBluetoothDevice

java.lang.RuntimeException: Stub!
at org.json.JSONObject.<init>(JSONObject.java:4)

This is under IntelliJ with the project set up following the guide (which by the way, needs some additional tweaks to work with IntelliJ 10).

I have set up the order of libraries so that Android is last in the dependencies and can run the test provided in the quick start.

Looking through the robolectric-1.0-RC1-jar-with-dependencies.jar I don't see any org.json classes in there so it seems like this is missing again?

Any thoughts?

--
Jeremy Wadsack

Jeremy Wadsack

unread,
Apr 20, 2011, 1:32:12 PM4/20/11
to robol...@googlegroups.com
Some additional information. I'm also getting these warnings when compiling which appears to come from the robolectric library (or maybe the junit one):

(javassist.ClassPool$1) that doesn't come with an
associated EnclosingMethod attribute. This class was probably produced by a
compiler that did not target the modern .class file format. The recommended
solution is to recompile the class from source, using an up-to-date compiler        
and without specifying any "-target" type options. The consequence of ignoring        
this warning is that reflective operations on this class will incorrectly        
indicate that it is *not* an inner class.
    
Any ideas? 

--
Jeremy Wadsack

Jeremy Wadsack

unread,
Apr 22, 2011, 5:01:18 PM4/22/11
to robol...@googlegroups.com
So, FWIW, adding the JSON jar (downloaded from source) to my test libraries resolved this for me for the time being.

However, looking through build.xml and the current source (or the source for the 1.0-RC1 tag) I can't see why this wouldn't have included JSON in the build.

--
Jeremy Wadsack

E.Norm

unread,
Sep 21, 2012, 11:00:09 PM9/21/12
to robol...@googlegroups.com
Hi and thx to Jeremy for pointing to github. I encountered my first stub! error, when I tried to use HttpClient (org.apache.http.client.HttpClient). I could work around this, by adding the android.jar from my harddisk in (C:\Appz\Android\android-sdk\platforms\android-15) to the build-path before the roboelectric.jar in the test-project. With JSON [http://developer.android.com/reference/org/json/package-summary.html] it did not work. After importing the json.jar from github, it eats the json from the yahoo-geo api. New possibilities. I'm glad I started searching for a thing like roboelectric as I really can see, after 2 days of tryout, that it will speed up my learning process with android, as no endless compile-dex-package-transfer-to-phone coffee-breaks are in my way. As long as I'm doing the backend. I'm not sure how roboelectric copes with the GUI of my app.

In the last post from Friday, August 19, 2011 on [http://robolectric.blogspot.de/] the Roboelectric team is describing the shadowing and no-op implentation which leads to _a_ stub! They too explain how to write mockups for unimplented android functionality, if there is any.
Reply all
Reply to author
Forward
0 new messages