在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数据。)因此,从启动画面类调用intent无效。
这是我得到的日志
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)
答案 0 :(得分:21)
我没有看到asynctask有任何问题。问题似乎与您的模拟器有关。尝试重新启动它。也许这个链接可以帮助您:EGL_emulation failed to establish connection to host - android