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

时间:2021-01-10 20:52:32

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

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