Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

java.lang.ExceptionInInitializerError on android #72

Open
joshgontijo opened this issue Oct 12, 2017 · 0 comments
Open

java.lang.ExceptionInInitializerError on android #72

joshgontijo opened this issue Oct 12, 2017 · 0 comments

Comments

@joshgontijo
Copy link
Owner

From #76

Hello,

I'm trying to integrate my android project with unirest. I followed manual at http://blog.mashape.com/using-unirest-java-for-your-android-projects/ and my project is successfully compiled. But when I try to create simple activity which gets google.com I have a runtime exception. Here is my activity:

package com.example.stas.testapp;

import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;

import com.mashape.unirest.http.Unirest;
import com.mashape.unirest.http.exceptions.UnirestException;


public class MainActivity extends ActionBarActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        TextView text = (TextView) findViewById(R.id.mainText);
        try {
            text.setText(Unirest.get("http://google.com").asString().getBody());
        }catch (UnirestException e){
            throw new RuntimeException(e);
        }
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}

And here's exception I got:

03-11 15:43:35.395: E/AndroidRuntime(26171): java.lang.ExceptionInInitializerError
03-11 15:43:35.395: E/AndroidRuntime(26171):    at com.mashape.unirest.http.HttpClientHelper.prepareRequest(HttpClientHelper.java:154)
03-11 15:43:35.395: E/AndroidRuntime(26171):    at com.mashape.unirest.http.HttpClientHelper.request(HttpClientHelper.java:134)
03-11 15:43:35.395: E/AndroidRuntime(26171):    at com.mashape.unirest.request.BaseRequest.asString(BaseRequest.java:56)
03-11 15:43:35.395: E/AndroidRuntime(26171):    at com.example.stas.testapp.MainActivity.onCreate(MainActivity.java:22)
03-11 15:43:35.395: E/AndroidRuntime(26171):    at android.app.Activity.performCreate(Activity.java:5188)
03-11 15:43:35.395: E/AndroidRuntime(26171):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
03-11 15:43:35.395: E/AndroidRuntime(26171):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2074)
03-11 15:43:35.395: E/AndroidRuntime(26171):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2135)
03-11 15:43:35.395: E/AndroidRuntime(26171):    at android.app.ActivityThread.access$700(ActivityThread.java:140)
03-11 15:43:35.395: E/AndroidRuntime(26171):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1237)
03-11 15:43:35.395: E/AndroidRuntime(26171):    at android.os.Handler.dispatchMessage(Handler.java:99)
03-11 15:43:35.395: E/AndroidRuntime(26171):    at android.os.Looper.loop(Looper.java:137)
03-11 15:43:35.395: E/AndroidRuntime(26171):    at android.app.ActivityThread.main(ActivityThread.java:4921)
03-11 15:43:35.395: E/AndroidRuntime(26171):    at java.lang.reflect.Method.invokeNative(Native Method)
03-11 15:43:35.395: E/AndroidRuntime(26171):    at java.lang.reflect.Method.invoke(Method.java:511)
03-11 15:43:35.395: E/AndroidRuntime(26171):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
03-11 15:43:35.395: E/AndroidRuntime(26171):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
03-11 15:43:35.395: E/AndroidRuntime(26171):    at dalvik.system.NativeStart.main(Native Method)
03-11 15:43:35.395: E/AndroidRuntime(26171): Caused by: java.lang.ExceptionInInitializerError
03-11 15:43:35.395: E/AndroidRuntime(26171):    at org.apache.http.impl.conn.PoolingHttpClientConnectionManager$InternalConnectionFactory.<init>(PoolingHttpClientConnectionManager.java:494)
03-11 15:43:35.395: E/AndroidRuntime(26171):    at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.<init>(PoolingHttpClientConnectionManager.java:149)
03-11 15:43:35.395: E/AndroidRuntime(26171):    at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.<init>(PoolingHttpClientConnectionManager.java:138)
03-11 15:43:35.395: E/AndroidRuntime(26171):    at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.<init>(PoolingHttpClientConnectionManager.java:114)
03-11 15:43:35.395: E/AndroidRuntime(26171):    at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.<init>(PoolingHttpClientConnectionManager.java:105)
03-11 15:43:35.395: E/AndroidRuntime(26171):    at com.mashape.unirest.http.options.Options.refresh(Options.java:73)
03-11 15:43:35.395: E/AndroidRuntime(26171):    at com.mashape.unirest.http.options.Options.<clinit>(Options.java:46)
03-11 15:43:35.395: E/AndroidRuntime(26171):    ... 18 more
03-11 15:43:35.395: E/AndroidRuntime(26171): Caused by: java.lang.ExceptionInInitializerError
03-11 15:43:35.395: E/AndroidRuntime(26171):    at org.apache.http.impl.conn.ManagedHttpClientConnectionFactory.<init>(ManagedHttpClientConnectionFactory.java:72)
03-11 15:43:35.395: E/AndroidRuntime(26171):    at org.apache.http.impl.conn.ManagedHttpClientConnectionFactory.<init>(ManagedHttpClientConnectionFactory.java:84)
03-11 15:43:35.395: E/AndroidRuntime(26171):    at org.apache.http.impl.conn.ManagedHttpClientConnectionFactory.<clinit>(ManagedHttpClientConnectionFactory.java:59)
03-11 15:43:35.395: E/AndroidRuntime(26171):    ... 25 more
03-11 15:43:35.395: E/AndroidRuntime(26171): Caused by: java.lang.NoSuchFieldError: org.apache.http.message.BasicLineFormatter.INSTANCE
03-11 15:43:35.395: E/AndroidRuntime(26171):    at org.apache.http.impl.io.DefaultHttpRequestWriterFactory.<init>(DefaultHttpRequestWriterFactory.java:52)
03-11 15:43:35.395: E/AndroidRuntime(26171):    at org.apache.http.impl.io.DefaultHttpRequestWriterFactory.<init>(DefaultHttpRequestWriterFactory.java:56)
03-11 15:43:35.395: E/AndroidRuntime(26171):    at org.apache.http.impl.io.DefaultHttpRequestWriterFactory.<clinit>(DefaultHttpRequestWriterFactory.java:46)
03-11 15:43:35.395: E/AndroidRuntime(26171):    ... 28 more

Device Android version: 4.1.2
Gradle file:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.1"

    defaultConfig {
        applicationId "com.example.stas.testapp"
        minSdkVersion 15
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:21.0.2'
}

Help please, what I'm doing wrong?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant