override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
callPostReq()
val sm = someTask()
sm.execute()
}
inner class someTask(): AsyncTask<String, Int, Array<String>>() {
override fun doInBackground(vararg params: String): Array<String>? {
val conn: Connection= null!!
val url = "jdbc:mysql://localhost:3306/"
val dbName = "db-01"
val driver = "com.mysql.jdbc.Driver"
val cred = Properties()
cred.put("username","username")
cred.put("password","pasword")
try {
Class.forName(driver).newInstance()
conn = DriverManager.getConnection(url,cred)
println("Connected to the database")
conn.close()
println("Disconnected from database")
} catch (e: Exception) {
e.printStackTrace()
}
return null
}
}
Неустранимое исключение: AsyncTask # 1 Процесс: highway.dueamount, PID: 15746 java.lang.RuntimeException: Произошла ошибка при выполнении doInBackground () в android.os.AsyncTask $ 3.done (AsyncTask.Java: 325) в java.util.concurrent.FutureTask.finishCompletion (FutureTask.java:354) в java.util.concurrent.FutureTask.setException (FutureTask.java:223) в java.util.concurrent.FutureTaskrun (.java: 242) в android.os.AsyncTask $ SerialExecutor $ 1.run (AsyncTask.java:243) в java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1133) в java.util.concur.run (ThreadPoolExecutor.java:607) на java.lang.Thread.run (Thread.java:760) Вызывается: kotlin.KotlinNullPointerException at highway.dueamount.MainActivity $ someTask.doInBackground (MainActivity.kt: 60) на шоссе.dueamount.MainActivity $ someTask.doInBackground (MainActivity.kt: 57) на android.os.AsyncTask $ 2.call (AsyncTask.java:305) на java.util.concurrent.FutureTask.run (FutureTask.java:237) в android.os.AsyncTask $ SerialExecutor $ 1.run (AsyncTask.java:243) в java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1133) в java.util.concurrent.ThunPer $ThreadPoolExecutor.java:607) на java.lang.Thread.run (Thread.java:760)