Android Studio做登陆注册

1.报错:Caused by: android.os.NetworkOnMainThreadException

  原因:在Android 4.0以上,网络连接不能放在主线程上,不然就会报错android.os.NetworkOnMainThreadException。但是4.0下版本可以不会报错。

  解决方法:

  ①可以再Activity的onCreate()方法中加入这样一段代码,适用于网络请求数据量很小的话,如下

if (android.os.Build.VERSION.SDK_INT > 9) {

    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();

    StrictMode.setThreadPolicy(policy);

}

  ②启动一条子线程进行你的网络请求,推荐使用这种

// Android 4.0 之后不能在主线程中请求HTTP请求

            new Thread(new Runnable(){

                @Override

                public void run() {

                    cachedImage = asyncImageLoader.loadDrawable(imageUrl, position);

                    imageView.setImageDrawable(cachedImage);

                }

            }).start();

转自:https://blog.csdn.net/qq_29477223/article/details/81027716?depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromBaidu-1&utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromBaidu-1

2.报错: Caused by: java.net.ConnectException: Connection refused

  解决方法:

源代码:

String url = "jdbc:mysql://localhost:3306/bishe_shoes";

修改:

//模拟器默认把localhost或者127.0.0.1当做本身,在模拟器上可以用10.0.2.2代替127.0.0.1和localhost
String url = "jdbc:mysql://10.0.2.2:3306/bishe_shoes";
原文地址:https://www.cnblogs.com/qilin20/p/12776595.html