java.lang.RuntimeException: Unable to start activity ComponentInfo{com.autumn.book/com.autumn.book.MainActivity}: android.os.NetworkOnMainThreadException

时间:2021-08-19 00:38:40

不能把http请求写在主线程里,改为这样

        Runnable runnable = new Runnable() {
            public void run() {
                HttpClient.post2("Notification posted 通知标题: " + "通知内容:");
            }
        };
        new Thread(runnable).start();