java - 照着第一行代码第二版敲的前两部分代码,提示报错
迷茫
迷茫 2017-04-18 10:34:19
0
4
578

E/EGL_emulation: tid 14967: eglSurfaceAttrib(1146): error 0x3009 (EGL_BAD_MATCH)
W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0x93d4c080, error=EGL_BAD_MATCH
点击之后出现上面两行错误,虚拟机中显示加载失败,上网搜索好像是说虚拟机中禁止了在主线程中进行网络请求,不是很明白其中的解释,希望得到帮助。

迷茫
迷茫

业精于勤,荒于嬉;行成于思,毁于随。

reply all(4)
洪涛

In this case, try putting the network request code in a sub-thread

Peter_Zhu

Network request is a time-consuming operation. For example, if you use NetEase News app to load news, it will take a long time to load when the network is not good. If this network request operation is executed in Activity, it will wait for the return result, causing this Activity It is stuck here and cannot respond to other operations, which is often said that the main thread is blocked and causes ANR, so it is necessary to reopen a thread for network access, as follows:

protected void onCreate(Bundle savedInstanceState){
...

 new Thread(new Runnable() {
            @Override
            public void run() {          
             //此处应为你网络请求的代码,通过Hanlder传递给主线程Activity处理
            }
        }).start();
}
黄舟

Android currently cannot perform network operations in the main thread. Network operations need to be executed in sub-threads, and some other time-consuming operations also need to be executed in sub-threads. If you put those time-consuming operations If all the time-consuming operations are executed in the main thread, then when the main thread executes these time-consuming operations, it will be blocked here, which is not good for the user experience, and an ANR exception will be reported after a long time.

小葫芦

Every language has shortcomings and advantages. For example, Java does not have closures. Everything is an object. The agent is weak in wit. The code written is long and inefficient. The amount of code can easily reach hundreds of thousands. Various frameworks are countless and cumbersome. The configuration and so on are very annoying

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!