6

AsyncTask在方法完成后尝试启动意图时遇到问题onPostExecute。我第一次调用AsyncTask是在启动屏幕活动中。

public class SplashScreen extends Activity {

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

       startJsonGet();
    }

    public void startJsonGet() {
        JsonGet getData = new JsonGet(mBuildings, SplashScreen.this);
        getData.execute();

    }
}

这调用了JsonGet

public class JsonGet extends AsyncTask<Void, Void, Void> {

    Context context;

    JsonGet(ArrayList<Building> mBuildings, Context context){
        super();
        this.mBuildings = mBuildings;
        this.context = context;
    }

    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        // before making http calls

    }

    @Override
    protected Void doInBackground(Void... arg0) {
        JsonParser jsonParser = new JsonParser();
        String json = jsonParser
                .getJSONFromUrl("");

        Log.e("Response: ", "> " + json);


        if (json != null) {
            try {

               //Does stuff
                }

            } catch (JSONException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

        }

        return null;
    }

    @Override
    protected void onPostExecute(Void result) {
        super.onPostExecute(result);
        Intent i=new Intent(context, MainActivity.class);
        context.startActivity(i);

    }

}

JSON 解析正确,日志显示了这一点。但是当我尝试在帖子中调用意图时,它会崩溃。我需要JsonGet从不同的类调用这个函数。(例如:当用户单击刷新按钮时更新 Json 数据。)因此从启动屏幕类调用意图将不起作用。

这是我得到的日志

    10-25 16:03:12.156    8481-8481/com.andrewcode.broncomaps E/eglCodecCommon﹕ writeFully: failed: Broken pipe
10-25 16:03:12.156    8481-8481/com.andrewcode.broncomaps E/EGL_emulation﹕ tid 8481: eglChooseConfig(576): error 0x3001 (EGL_NOT_INITIALIZED)
10-25 16:03:12.164    8481-8481/com.andrewcode.broncomaps E/AndroidRuntime﹕ FATAL EXCEPTION: main
    java.lang.IllegalArgumentException: eglChooseConfig failed EGL_NOT_INITIALIZED
            at android.view.HardwareRenderer$GlRenderer.chooseEglConfig(HardwareRenderer.java:893)
            at android.view.HardwareRenderer$GlRenderer.initializeEgl(HardwareRenderer.java:845)
            at android.view.HardwareRenderer$GlRenderer.initialize(HardwareRenderer.java:786)
            at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1502)
            at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:989)
            at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4351)
            at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
            at android.view.Choreographer.doCallbacks(Choreographer.java:562)
            at android.view.Choreographer.doFrame(Choreographer.java:532)
            at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
            at android.os.Handler.handleCallback(Handler.java:725)
            at android.os.Handler.dispatchMessage(Handler.java:92)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:5041)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
            at dalvik.system.NativeStart.main(Native Method)
4

1 回答 1

21

我没有看到异步任务有任何问题。问题似乎出在您的模拟器上。尝试重新启动它。也许这个链接可以帮助你:EGL_emulation failed to build connection to host - android

于 2013-10-26T16:15:55.887 回答