???? java.lang.RuntimeException: Unable to start activity ComponentInfo ????

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: org.kotlin.async.task, PID: 6571
    java.lang.RuntimeException: Unable to start activity ComponentInfo{org.kotlin.async.task/org.kotlin.async.task.DownLoadActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ProgressBar.setProgress(int)' on a null object reference
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3539)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3699)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2135)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:236)
        at android.app.ActivityThread.main(ActivityThread.java:8037)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:656)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:967)
     Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ProgressBar.setProgress(int)' on a null object reference
        at org.kotlin.async.task.DownLoadActivity.onCreate(DownLoadActivity.java:36)
        at android.app.Activity.performCreate(Activity.java:8157)
        at android.app.Activity.performCreate(Activity.java:8129)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1310)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3512)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3699) 
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85) 
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) 
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2135) 
        at android.os.Handler.dispatchMessage(Handler.java:106) 
        at android.os.Looper.loop(Looper.java:236) 
        at android.app.ActivityThread.main(ActivityThread.java:8037) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:656) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:967) 
I/Process: Sending signal. PID: 6571 SIG: 9

出现问题的原因

onCreate函数里面加载的布局文件 activity_main.xml 不存在 ProgressBar 组件

在activity_main.xml里面定义ProgressBar的组件布局

????  java.io.IOException: Cleartext HTTP traffic to download.sj.qq.com not permitted ????

W/System.err: java.io.IOException: Cleartext HTTP traffic to download.sj.qq.com not permitted
W/System.err:     at com.android.okhttp.HttpHandler$CleartextURLFilter.checkURLPermitted(HttpHandler.java:127)
W/System.err:     at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:462)
W/System.err:     at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:411)
W/System.err:     at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:248)
W/System.err:     at org.kotlin.async.task.DownLoadActivity$Myasynctask.doInBackground(DownLoadActivity.java:99)
W/System.err:     at org.kotlin.async.task.DownLoadActivity$Myasynctask.doInBackground(DownLoadActivity.java:47)
W/System.err:     at android.os.AsyncTask$3.call(AsyncTask.java:394)
W/System.err:     at java.util.concurrent.FutureTask.run(FutureTask.java:266)
W/System.err:     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:305)
W/System.err:     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
W/System.err:     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
W/System.err:     at java.lang.Thread.run(Thread.java:923)

出现问题的原因

Android9.0 默认是不允许网络请求http链接

AndroidManifest.xml 文件里面 application 标签下配置 android:usesCleartextTraffic="true"

<application
        ......
        android:usesCleartextTraffic="true">
</application>

比Android9.0更高的版本配置 , 需要在res文件夹下创建xml文件夹并且在xml文件夹下创建network_security_config.xml文件

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <base-config cleartextTrafficPermitted="true"/>
</network-security-config>

最后在 AndroidManifest.xml 文件里面 application 标签下配置 network_security_config.xml

<application
       .....
       android:networkSecurityConfig="@xml/network_security_config"
</application>