手机
当前位置:查字典教程网 >编程开发 >安卓软件开发 >Android Studio 2.2.3 http访问抛出异常问题
Android Studio 2.2.3 http访问抛出异常问题
摘要:atcom.example.asen.work8.MainActivity$2$1.run(MainActivity.java:65)W/S...

at com.example.asen.work8.MainActivity$2$1.run(MainActivity.java:65)

W/System.err: Caused by: android.system.ErrnoException: connect failed: ENETUNREACH (Network is unreachable)

65行的句子:if (conn.getResponseCode() == 200)

访问代码

private static final String PATH = "http://192.168.56.1:8080/loginService/login.jsp";

private void initListener() {

        button01.setOnClickListener(new View.OnClickListener() {

            @Override

            public void onClick(View v) {

                Thread thread = new Thread() {

                    @Override

                    public void run() {

                        String name = edit1.getText().toString();

                        String psw = edit2.getText().toString();

                        String path = PATH + "?username=" + name + "&password=" + psw;

                        try {

                            URL url = new URL(path);

                            HttpURLConnection conn = (HttpURLConnection)url.openConnection();

                            conn.setRequestMethod("GET");

                            if (conn.getResponseCode() == 200) {

                                InputStream is = conn.getInputStream();

                                String result = parseIS(is);

                                Message msg = new Message();

                                Bundle bundle = new Bundle();

                                bundle.putString(MESSAGE_TITLE, result);

                                msg.setData(bundle);

                                handler.sendMessage(msg);

                            }

                        } catch (IOException ex) {

                            ex.printStackTrace();

                            String result = ex.toString();

                            Message msg = new Message();

                            Bundle bundle = new Bundle();

                            bundle.putString(MESSAGE_TITLE, result);

                            msg.setData(bundle);

                            handler.sendMessage(msg);

                        }

                    }

                };

                thread.start();

            }

        });

    }

求问这个异常要怎么解决啊,ip地址我用了虚拟的ip,tomcat用这个ip也可以进去

回复讨论(解决方案)

另外我测试用的是genymotion Samsung Galaxy S7-6.0.0-API 23  网络无法访问 我换成AS自带的模拟器就可以用了。。。

【Android Studio 2.2.3 http访问抛出异常问题】相关文章:

深入Android线程的相关问题解惑

Android Studio打包时解决V4包重复的问题

基于Android ListView之加载使用技巧

Android Studio使用教程图文详解

android textview 显示html方法解析

Android实现隐藏状态栏和标题栏

Android软件开发环境搭建

Android动态添加View的问题解决方法

android USB如何修改VID具体实现

Android SlidingDrawer 抽屉效果的实现

精品推荐
分类导航