[SOLVED] Android app is crashing on new ApiClient(API_KEY)

Hi,

i am making an android app connect and send variablevalues to ubidots. I am trying to make a simple example based on the Ubidots example android app.

Everyhting compiles without errors, but when i run the application and try to connect to Ubidots, the app crashes with this callstack:

10-15 17:53:04.303: E/AndroidRuntime(7867): FATAL EXCEPTION: AsyncTask #1
10-15 17:53:04.303: E/AndroidRuntime(7867): Process: com.example.unoPidGuiPrototype, PID: 7867
10-15 17:53:04.303: E/AndroidRuntime(7867): java.lang.RuntimeException: An error occured while executing doInBackground()
10-15 17:53:04.303: E/AndroidRuntime(7867): at android.os.AsyncTask$3.done(AsyncTask.java:304)
10-15 17:53:04.303: E/AndroidRuntime(7867): at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
10-15 17:53:04.303: E/AndroidRuntime(7867): at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
10-15 17:53:04.303: E/AndroidRuntime(7867): at java.util.concurrent.FutureTask.run(FutureTask.java:242)
10-15 17:53:04.303: E/AndroidRuntime(7867): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
10-15 17:53:04.303: E/AndroidRuntime(7867): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
10-15 17:53:04.303: E/AndroidRuntime(7867): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
10-15 17:53:04.303: E/AndroidRuntime(7867): at java.lang.Thread.run(Thread.java:818)
10-15 17:53:04.303: E/AndroidRuntime(7867): Caused by: java.lang.NoSuchFieldError: No static field INSTANCE of type Lorg/apache/http/message/BasicLineFormatter; in class Lorg/apache/http/message/BasicLineFormatter; or its superclasses (declaration of ‘org.apache.http.message.BasicLineFormatter’ appears in /system/framework/ext.jar)
10-15 17:53:04.303: E/AndroidRuntime(7867): at org.apache.http.impl.io.DefaultHttpRequestWriterFactory.(DefaultHttpRequestWriterFactory.java:52)
10-15 17:53:04.303: E/AndroidRuntime(7867): at org.apache.http.impl.io.DefaultHttpRequestWriterFactory.(DefaultHttpRequestWriterFactory.java:56)
10-15 17:53:04.303: E/AndroidRuntime(7867): at org.apache.http.impl.io.DefaultHttpRequestWriterFactory.(DefaultHttpRequestWriterFactory.java:46)
10-15 17:53:04.303: E/AndroidRuntime(7867): at org.apache.http.impl.conn.ManagedHttpClientConnectionFactory.(ManagedHttpClientConnectionFactory.java:72)
10-15 17:53:04.303: E/AndroidRuntime(7867): at org.apache.http.impl.conn.ManagedHttpClientConnectionFactory.(ManagedHttpClientConnectionFactory.java:84)
10-15 17:53:04.303: E/AndroidRuntime(7867): at org.apache.http.impl.conn.ManagedHttpClientConnectionFactory.(ManagedHttpClientConnectionFactory.java:59)
10-15 17:53:04.303: E/AndroidRuntime(7867): at org.apache.http.impl.conn.PoolingHttpClientConnectionManager$InternalConnectionFactory.(PoolingHttpClientConnectionManager.java:487)
10-15 17:53:04.303: E/AndroidRuntime(7867): at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.(PoolingHttpClientConnectionManager.java:147)
10-15 17:53:04.303: E/AndroidRuntime(7867): at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.(PoolingHttpClientConnectionManager.java:136)
10-15 17:53:04.303: E/AndroidRuntime(7867): at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.(PoolingHttpClientConnectionManager.java:112)
10-15 17:53:04.303: E/AndroidRuntime(7867): at org.apache.http.impl.client.HttpClientBuilder.build(HttpClientBuilder.java:726)
10-15 17:53:04.303: E/AndroidRuntime(7867): at com.ubidots.ServerBridge.postWithApiKey(ServerBridge.java:82)
10-15 17:53:04.303: E/AndroidRuntime(7867): at com.ubidots.ServerBridge.recieveToken(ServerBridge.java:72)
10-15 17:53:04.303: E/AndroidRuntime(7867): at com.ubidots.ServerBridge.initialize(ServerBridge.java:67)
10-15 17:53:04.303: E/AndroidRuntime(7867): at com.ubidots.ServerBridge.(ServerBridge.java:54)
10-15 17:53:04.303: E/AndroidRuntime(7867): at com.ubidots.ServerBridge.(ServerBridge.java:43)
10-15 17:53:04.303: E/AndroidRuntime(7867): at com.ubidots.ApiClient.(ApiClient.java:16)
10-15 17:53:04.303: E/AndroidRuntime(7867): at com.example.unoPidGuiPrototype.HomeActivity$ApiUbidots.doInBackground(HomeActivity.java:156)
10-15 17:53:04.303: E/AndroidRuntime(7867): at com.example.unoPidGuiPrototype.HomeActivity$ApiUbidots.doInBackground(HomeActivity.java:146)
10-15 17:53:04.303: E/AndroidRuntime(7867): at android.os.AsyncTask$2.call(AsyncTask.java:292)
10-15 17:53:04.303: E/AndroidRuntime(7867): at java.util.concurrent.FutureTask.run(FutureTask.java:237)
10-15 17:53:04.303: E/AndroidRuntime(7867): … 4 more

I think the problem is that the SDK version of package org.apache.http is used instead of the one that is provided with the ubidots library, but I cannot figure out how to configure the Intelij Idea project to fix this.

Any suggestion would be helpful, thanks

Hey @nameless_one, it’s really weird. I just made yesterday an app using the library and got it working good so far in Android 4.3, Android 5.1 and Android 6.0.1.
But let’s try to fix your error so you can use Ubidots and send your values :smiley:

Can you try to do what this answer from StackOverflow tells?

If you’re not able to fix the problem with that, please give me a bit more information of your project. For example, what does your code in doInBackground looks like; what version of SDK are you using (minSdkVersion) and your Android version. So I can test it better.

Regards :blush:

Yes I have seen that post on StackOverflow, but I dont know how to tell to the buildin compiler in Intelij IDEA ide to exclude the httpclient module and instead use the one provided in ubidots module.

Anyway, after trying to fix this for sereval hours I decided to take a different approach. I threw away the Ubidots android library completely and insead I used the OkHttp library to construct and send requests to Ubidots REST API. It is working like a charm.

I’m glad that you were able to connect to Ubidots using OkHttp.

We’re listening continuously to our users, and thanks to your report we will evaluate rewriting the library with a different approach (maybe use Volley) that doesn’t seem to have problems with newest SDK versions. I hope we can contact you soon with great news.

Thanks so much :smile: