Roboguice / Guice ComputationException при первой инициализации инжектора в фоновом потоке - PullRequest
0 голосов
/ 31 августа 2011

Исключение не возникает при создании инжектора в потоке пользовательского интерфейса.Я использую RoboSplashActivity.

Вот класс активности всплеска:

package com.example.view;

import roboguice.activity.RoboSplashActivity;
import roboguice.application.RoboApplication;
import roboguice.inject.ContextScope;

import com.aa.jetaway.R;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.DialogInterface.OnClickListener;
import android.os.Bundle;
import android.os.Handler;
/*snipped some imports here that are identifiable */

public class SplashActivity extends RoboSplashActivity {
    @Override public void onCreate(Bundle bundle) {
        setContentView(R.layout.splash);

/*

When the following two lines are uncommented, everything works, except that all the long-delayed stuff is happening in the UI thread -- not in the background w/a pretty splash page

 */
//      RoboApplication app = (RoboApplication) getApplication();
//        ContextScope scope = app.getInjector().getInstance(ContextScope.class);


        super.onCreate(bundle);
    }

    @Override protected void doStuffInBackground(RoboApplication app) {
        CachedData.onAppLaunch(app);
        WebServiceClient.onAppLaunch(app);

    }

    public void startNextActivity() {
        Intent intent = new Intent(this, LoginActivity.class);
        startActivity(intent);
        finish();
    }

}

Когда строки комментируются, я получаю эту ошибку:

08-31 13: 17:30.671: ERROR/AndroidRuntime(10566): com.google.inject.internal.ComputationException: java.lang.ExceptionInInitializerError
    08-31 13:17:30.671: ERROR/AndroidRuntime(10566):     at com.google.inject.internal.MapMaker$StrategyImpl.compute(MapMaker.java:553)
    08-31 13:17:30.671: ERROR/AndroidRuntime(10566):     at com.google.inject.internal.MapMaker$StrategyImpl.compute(MapMaker.java:419)
    08-31 13:17:30.671: ERROR/AndroidRuntime(10566):     at com.google.inject.internal.CustomConcurrentHashMap$ComputingImpl.get(CustomConcurrentHashMap.java:2041)
    08-31 13:17:30.671: ERROR/AndroidRuntime(10566):     at com.google.inject.internal.FailableCache.get(FailableCache.java:46)
    08-31 13:17:30.671: ERROR/AndroidRuntime(10566):     at com.google.inject.ConstructorInjectorStore.get(ConstructorInjectorStore.java:52)
    08-31 13:17:30.671: ERROR/AndroidRuntime(10566):     at com.google.inject.ConstructorBindingImpl.initialize(ConstructorBindingImpl.java:57)
    08-31 13:17:30.671: ERROR/AndroidRuntime(10566):     at com.google.inject.InjectorImpl.initializeBinding(InjectorImpl.java:377)
    08-31 13:17:30.671: ERROR/AndroidRuntime(10566):     at com.google.inject.BindingProcessor$1$1.run(BindingProcessor.java:169)
    08-31 13:17:30.671: ERROR/AndroidRuntime(10566):     at com.google.inject.BindingProcessor.initializeBindings(BindingProcessor.java:224)
    08-31 13:17:30.671: ERROR/AndroidRuntime(10566):     at com.google.inject.InjectorBuilder.initializeStatically(InjectorBuilder.java:120)
    08-31 13:17:30.671: ERROR/AndroidRuntime(10566):     at com.google.inject.InjectorBuilder.build(InjectorBuilder.java:105)
    08-31 13:17:30.671: ERROR/AndroidRuntime(10566):     at com.google.inject.Guice.createInjector(Guice.java:92)
    08-31 13:17:30.671: ERROR/AndroidRuntime(10566):     at roboguice.application.RoboApplication.createInjector(RoboApplication.java:146)
    08-31 13:17:30.671: ERROR/AndroidRuntime(10566):     at roboguice.application.RoboApplication.getInjector(RoboApplication.java:84)
    08-31 13:17:30.671: ERROR/AndroidRuntime(10566):     at roboguice.activity.RoboSplashActivity$1.run(RoboSplashActivity.java:38)
    08-31 13:17:30.671: ERROR/AndroidRuntime(10566):     at java.lang.Thread.run(Thread.java:1102)
    08-31 13:17:30.671: ERROR/AndroidRuntime(10566): Caused by: java.lang.ExceptionInInitializerError
    08-31 13:17:30.671: ERROR/AndroidRuntime(10566):     at java.lang.Class.getDeclaredConstructors(Native Method)
    08-31 13:17:30.671: ERROR/AndroidRuntime(10566):     at java.lang.Class.getDeclaredConstructors(Class.java:615)
    08-31 13:17:30.671: ERROR/AndroidRuntime(10566):     at com.google.inject.spi.InjectionPoint.forConstructorOf(InjectionPoint.java:185)
    08-31 13:17:30.671: ERROR/AndroidRuntime(10566):     at com.google.inject.ConstructorInjectorStore.createConstructor(ConstructorInjectorStore.java:61)
    08-31 13:17:30.671: ERROR/AndroidRuntime(10566):     at com.google.inject.ConstructorInjectorStore.access$000(ConstructorInjectorStore.java:31)
    08-31 13:17:30.671: ERROR/AndroidRuntime(10566):     at com.google.inject.ConstructorInjectorStore$1.create(ConstructorInjectorStore.java:39)
    08-31 13:17:30.671: ERROR/AndroidRuntime(10566):     at com.google.inject.ConstructorInjectorStore$1.create(ConstructorInjectorStore.java:35)
    08-31 13:17:30.671: ERROR/AndroidRuntime(10566):     at com.google.inject.internal.FailableCache$1.apply(FailableCache.java:35)
    08-31 13:17:30.671: ERROR/AndroidRuntime(10566):     at com.google.inject.internal.MapMaker$StrategyImpl.compute(MapMaker.java:549)
    08-31 13:17:30.671: ERROR/AndroidRuntime(10566):     ... 15 more
    08-31 13:17:30.671: ERROR/AndroidRuntime(10566): Caused by: java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
    08-31 13:17:30.671: ERROR/AndroidRuntime(10566):     at android.os.Handler.<init>(Handler.java:121)
    08-31 13:17:30.671: ERROR/AndroidRuntime(10566):     at android.os.AsyncTask$InternalHandler.<init>(AsyncTask.java:421)
    08-31 13:17:30.671: ERROR/AndroidRuntime(10566):     at android.os.AsyncTask$InternalHandler.<init>(AsyncTask.java:421)
    08-31 13:17:30.671: ERROR/AndroidRuntime(10566):     at android.os.AsyncTask.<clinit>(AsyncTask.java:152)
    08-31 13:17:30.671: ERROR/AndroidRuntime(10566):     ... 24 more

У любого есть любойпредложения?

1 Ответ

0 голосов
/ 01 сентября 2011

Это было результатом моих попыток внедрить элементы пользовательского интерфейса. Все работало отлично, пока я не попытался создать инжектор в фоновом потоке.

Ответ: не вводите ProgressDialogs и т. Д.

...